Android系统编译so库提示error undefined reference to '__android_log_print问题的解决

在系统源代码的hardware/qcom下增加psam文件夹,编译源代码要生成libpsam.so库,Android.mk内容

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

 

LOCAL_MODULE       := libpsam

LOCAL_SRC_FILES       := psam.c

LOCAL_MODULE_TAGS  := optional

LOCAL_MODULE_CLASS := SHARED_LIBRARIES

include $(BUILD_SHARED_LIBRARY)

 

但编译出错,提示error undefined reference to '__android_log_print错误,__android_log_print在system\core\liblog\logd_writer.c

 

这个错误表示找不到__android_log_print的引用,错误原因可能是so文件没有没有添加log的链接库,所以我们需要在在Android.mk中添加log的链接库;

 

解决方法有两种方法:

------------------------------方法1-----------------------------------------

增加LOCAL_LDLIBS    := -llog

LOCAL_LDFLAGS:这个编译变量传递给链接器一个一些额外的参数,比如想传递额外的库和库路径给ld,或者传递给ld linker的一些链接参数,-On,-EL{B}(大小端字节序),那么就要加到这个上面,如:

LOCAL_LDFLAGS += -L$(LOCAL_PATH)/lib/ -lHWrecog –EB{EL} –O{n} …

或者直接加上绝对路径库的全名:

LOCAL_LDFLAGS += $(LOCAL_PATH)/lib/libHWrecog.a –EB{EL} –O{n}

------------------------------方法2-----------------------------------------

增加LOCAL_SHARED_LIBRARIES相关

LOCAL_SHARED_LIBRARIES := \

        libnativehelper \

              libcutils

LOCAL_SHARED_LIBRARIES 会生成依赖关系,当库不存在时会去编译这个库。

 

 

猜你喜欢

转载自blog.csdn.net/LoongEmbedded/article/details/85338005