ndk连接第三方库

看ndk说明文档关于第三方库(Prebuilts)的用法,安装上面的方法试了下,结果老是连接不上,第三方库中的函数连接不到:

Administrator@4ec48ba026e34ae /cygdrive/e/myprj/hello-jni/jni
$ /cygdrive/e/work/android-ndk-r5b/ndk-build
Compile thumb  : hello-jni <= hello-jni.c
SharedLibrary  : libhello-jni.so
E:/myprj/hello-jni/obj/local/armeabi/objs/hello-jni/hello-jni.o: In function `
st1':
E:/myprj/hello-jni/jni/hello-jni.c:12: undefined reference to `InitWordInfo'
E:/myprj/hello-jni/jni/hello-jni.c:21: undefined reference to `debug_printf'
E:/myprj/hello-jni/jni/hello-jni.c:24: undefined reference to `debug_printf'
E:/myprj/hello-jni/jni/hello-jni.c:43: undefined reference to `debug_printf'
E:/myprj/hello-jni/jni/hello-jni.c:62: undefined reference to `debug_printf'
E:/myprj/hello-jni/jni/hello-jni.c:16: undefined reference to `debug_printf'
E:/myprj/hello-jni/obj/local/armeabi/objs/hello-jni/hello-jni.o:E:/myprj/hello
ni/jni/hello-jni.c:78: more undefined references to `debug_printf' follow
collect2: ld returned 1 exit status
make: *** [/cygdrive/e/myprj/hello-jni/obj/local/armeabi/libhello-jni.so] Erro
1


后来在网上查到原因,原来是可恶Prebuilts文档有错误

http://hi.baidu.com/nalch/blog/item/f6a1ed6aec69d2cd80cb4a59.html

LOCAL_SHARED_LIBRARIES和LOCAL_SHARED_LIBRARY:注意前者是复数S形式,用于Link多个库(只有一个也可以用),后者只能添加一个链接库,可恶的文档关于Prebuilts的介绍里面给出的例子是LOCAL_SHARED_LIBRARY,使用两个库的时候第二个库死也link不上。


Android.mk修改后,就可以连接通过了。

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := my-init
LOCAL_SRC_FILES := libinit.so
#LOCAL_SRC_FILES := ../../sojni/libs/armeabi/libinit.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
#LOCAL_SHARED_LIBRARY := my-init    #应该用复数形式,否则连接不上第三方库中的函数
LOCAL_SHARED_LIBRARIES := my-init
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)

你可能感兴趣的:(function,Module,文档,include,library,reference)