“collect2: ld returned 1 exit status”错误

“collect2: ld returned 1 exit status”错误

      今天在编译android JNI时碰到个问题,错误log如下:

    
make:进入目录'/home/zhangfang/zf/DM3730/source/android_source/TI_Android_GingerBread_2_3_4Sources'
target thumb C: libzf <= external/JNIZhangFangTest/jni/com_android_zhang_test_JNIZhangFangTestActivity.c
target SharedLib: libzf (out/target/product/omap3evm/obj/SHARED_LIBRARIES/libzf_intermediates/LINKED/libzf.so)
prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/../lib/gcc/arm-eabi/4.4.3/../../../../arm-eabi/bin/ld: out/target/product/omap3evm/obj/SHARED_LIBRARIES/libzf_intermediates/com_android_zhang_test_JNIZhangFangTestActivity.o: in function hello_init:external/JNIZhangFangTest/jni/com_android_zhang_test_JNIZhangFangTestActivity.c:93: error: undefined reference to 'hw_get_module'
collect2: ld returned 1 exit status
make: *** [out/target/product/omap3evm/obj/SHARED_LIBRARIES/libzf_intermediates/LINKED/libzf.so] 错误 1


错误原因分析:
hw_get_module找不到,为什么会找不到呢?不是包含头文件#include 了吗?
其实,其真实原因是使用了hw_get_module这个函数,在链接的时候需要到libhardware.so库中去找,但是在Android.mk中却没有包含libhareware.so库,所以在链接的时候报错。
解决方法:
在Android.mk中加入该库即可:

LOCAL_SHARED_LIBRARIES := libutils libhardware


     ps: “collect2: ld returned 1 exit status”,这个错误时因为在使用xxxxxx.so库时,库中的xxxxxxxx函数需要其他库文件或者没有实现。所以只需要将相应的库文件加到编译的路徑中.

你可能感兴趣的:(android,系统开发)