V3s 项目 CamDroid 编译第三方程序 / V1.0
第 1 页共 9 页 文档履历 版本号日期制 / 修订人内容描述 V1.0 2014-04-23 正式版本
第 2 页共 9 页 目录 1. 交叉编译环境... 3 2. 第三方库的 Makefile 示例... 4 3. 第三方应用 Makefile 示例... 5 4. 第三方应用 CamLinux.mk 示例... 6 5. 常见错误... 7 5.1 -lpthread 找不到库...7 5.2 exidx_start exidx_end 错误 (Android4.2 ndk8 bug)... 7
第 3 页共 9 页 1. 交叉编译环境 交叉编译工具 arm-linux-androideabi- 使用的动态链接库 SYSTEM_LIB BASE_LIB 使用的头文件 SYSTEM_INCLUDE BASE_INCLUDE
第 4 页共 9 页 2. 第三方库的 Makefile 示例 TARGET=libdemo.so SHARED=-shared FPIC=-fPIC BASE_ENV=xxx/cdr/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin CROSS=arm-linux-androideabi- CC = $(BASE_ENV)/$(CROSS)gcc CPP = $(BASE_ENV)/$(CROSS)g++ STRIP = $(BASE_ENV)/$(CROSS)strip AR = $(BASE_ENV)/$(CROSS)ar LD = $(BASE_ENV)/$(CROSS)ld BASE=xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-arm/usr BASE_LIB=$(BASE)/lib BASE_INCLUDE=$(BASE)/include LDFLAGS=-L$(BASE_LIB) LDFLAGS += -nostdlib -lstdc++ -lc -ldl -Bdynamic -Wl,-dynamic-linker,/system/bin/linker EXTRA_OBJS = $(BASE_LIB)/crtbegin_dynamic.o $(BASE_LIB)/crtend_android.o CFLAGS =-Wall -O0 -g INCLUDES:=$(foreach dir,$(srcdirs),-i$(dir)) INCLUDES+= -I(BASE_INCLUDE) BUILDPATH=. SRCDIRS:=. DATA_SRC=file SRCCS=$(foreach dir,$(srcdirs),$(wildcard $(dir)/*.c)) LIBOBJ=$(addprefix $(BUILDPATH)/, $(addsuffix.o, $(basename $(SRCCS)))) all: $(TARGET) $(BUILDPATH)/%.o:%.c $(CC) $(CFLAGS) ${INCLUDES} $(FPIC) -o $@ -c $< $(TARGET):$(LIBOBJ) $(CC) $(LDFLAGS) $(SHARED) -o $@ $^ $(EXTRA_OBJS) $(LIBS) clean: rm -f $(TARGET) $(LIBOBJ)
第 5 页共 9 页 3. 第三方应用 Makefile 示例 TARGET=demo BASE_ENV=xxx/cdr/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.6/bin CROSS=arm-linux-androideabi- CC = $(BASE_ENV)/$(CROSS)gcc CPP = $(BASE_ENV)/$(CROSS)g++ STRIP = $(BASE_ENV)/$(CROSS)strip AR = $(BASE_ENV)/$(CROSS)ar LD = $(BASE_ENV)/$(CROSS)ld BASE=xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-arm/usr BASE_LIB=$(BASE)/lib BASE_INCLUDE=$(BASE)/include LDFLAGS=-L$(BASE_LIB)-L. LDFLAGS += -nostdlib -lstdc++ -lc -ldl -Bdynamic -Wl,-dynamic-linker,/system/bin/linker -ldemo EXTRA_OBJS = $(BASE_LIB)/crtbegin_dynamic.o $(BASE_LIB)/crtend_android.o CFLAGS =-Wall -O0 -g INCLUDES:=$(foreach dir,$(srcdirs),-i$(dir)) INCLUDES+= -I(BASE_INCLUDE) BUILDPATH=. SRCDIRS:=. DATA_SRC=file SRCCS=$(foreach dir,$(srcdirs),$(wildcard $(dir)/*.c)) LIBOBJ=$(addprefix $(BUILDPATH)/, $(addsuffix.o, $(basename $(SRCCS)))) all: $(TARGET) $(BUILDPATH)/%.o:%.c $(CC) $(CFLAGS) ${INCLUDES} -o $@ -c $< $(TARGET):$(LIBOBJ) $(CC) $(LDFLAGS) -o $@ $^ $(EXTRA_OBJS) $(LIBS) clean: rm -f $(TARGET) $(LIBOBJ)
第 6 页共 9 页 4. 第三方应用 CamLinux.mk 示例 LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../prebuilts -ldemo LOCAL_SRC_FILES := hello.c LOCAL_MODULE := hello include $(BUILD_EXECUTABLE)
第 7 页共 9 页 5. 常见错误 5.1 -lpthread 找不到库 Android 编译环境集成线程库至 libc 中, 从 libc 包含 pthread.h 可以看出, 仅需要链接 -lc 即可 5.2 exidx_start exidx_end 错误 (Android4.2( ndk8 bug) 应用编译完成, 执行阶段报类似下面的错误信息 Cannot load library: soinfo_relocate(linker.cpp:975): cannot locate symbol " exidx_end" referenced by 找不到这个符号, 解决方法, 在所编译的库中任一 c 文件中加入 : void exidx_start() {} void exidx_end() {} Tips: 编译时, 很多时候报 undefined function_xxx 之类找不到函数的错误 此时需要找到在 NDK 编译环境对应的库 解决方法是利用 grep 和 find 命令 用 grep -rns "function_xxx" xxx/cdr/ 命令查找包含这个函数定义的.h 文件或.so 文件 分析最有可能包含这个函数的对应 ndk 版本下的库 编译时链接这个库就可以 如找 time.h find xxx/cdr/prebuilts/ndk/8/platforms/android-14/ -name "time.h" xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-x86/usr/include/sys/time.h xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-x86/usr/include/linux/time.h xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-x86/usr/include/time.h xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-arm/usr/include/sys/time.h xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-arm/usr/include/linux/time.h xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-arm/usr/include/time.h xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-mips/usr/include/sys/time.h xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-mips/usr/include/linux/time.h xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-mips/usr/include/time.h 如找 pthread_create grep -rns "pthread_create" xxx/cdr/prebuilts/ndk/8/platforms/android-14/ xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-x86/usr/include/pthread.h:139:int pthread_create(pthread_t *thread, pthread_attr_t const * attr, 匹配到二进制文件 xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-x86/usr/lib/libc.a 匹配到二进制文件 xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-x86/usr/lib/libc.so xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-arm/usr/include/pthread.h:139:int pthread_create(pthread_t *thread, pthread_attr_t const * attr, 匹配到二进制文件 xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-arm/usr/lib/libc.a 匹配到二进制文件 xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-arm/usr/lib/libc.so
第 8 页共 9 页 xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-mips/usr/include/pthread.h:139:int pthread_create(pthread_t *thread, pthread_attr_t const * attr, 匹配到二进制文件 xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-mips/usr/lib/libc.a 匹配到二进制文件 xxx/cdr/prebuilts/ndk/8/platforms/android-14/arch-mips/usr/lib/libc.so
第 9 页共 9 页 Declaration This document is the original work and copyrighted property of Allwinner Technology ( Allwinner ). Reproduction in whole or in part must obtain the written approval of Allwinner and give clear acknowledgement to the copyright owner. The information furnished by Allwinner is believed to be accurate and reliable. Allwinner reserves the right to make changes in circuit design and/or specifications at any time without notice. Allwinner does not assume any responsibility and liability for its use. Nor for any infringements of patents or other rights of the third parties which may result from its use. No license is granted by implication or otherwise under any patent or patent rights of Allwinner. This datasheet neither states nor implies warranty of any kind, including fitness for any particular application.