undefined reference to `__android_log_print'

前端 未结 15 1950
不知归路
不知归路 2020-12-02 09:26

What is wrong with my make file?

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := foo
LOCAL_SRC_FILES := foo.c
LOCAL         


        
相关标签:
15条回答
  • 2020-12-02 10:07

    For Android Studio 2.2 and tools.build:gradle:2.2.0 using CMake add or edit row in CMakeLists.txt:

    target_link_libraries(<your_library_name> 
                          android 
                          log)
    

    Thats connecting log library to yours.

    0 讨论(0)
  • 2020-12-02 10:09

    -DCMAKE_CXX_FLAGS="-llog" helps me

    0 讨论(0)
  • 2020-12-02 10:11

    Try the following in your Android.mk file:

    LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
    
    0 讨论(0)
  • 2020-12-02 10:11

    Yes, you do need to add: LOCAL_LDLIBS := -llog as the other answers/comments have specified, however the original question did not specify if he use the jni library as: LOCAL_JNI_SHARED_LIBRARIES or as LOCAL_REQUIRED_MODULES.

    I can pretty much say for sure that he has it used it as: LOCAL_REQUIRED_MODULES because of the LOCAL_EXPORT_LDLIBS := -llog in the question... unless that was added after an edit.

    If you use LOCAL_REQUIRED_MODULES the shared library is installed in /system/lib instead of into the apk, because it is a required module. Therefore you will need to add LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog instead of just LOCAL_LDLIBS := -llog so that when the build system is building & linking the jni shared library, it will have the -llog definitions in the correct place, available to be built under $OUT/root/system/lib. Otherwise you will continue to get the same answer, even if you only add LOCAL_LDLIBS := -llog.

    So, those who commented that the -L is not needed, and the other answer was correct, they were actually incorrect in this situation.

    0 讨论(0)
  • 2020-12-02 10:14

    add LOCAL_SHARED_LIBRARIES:= liblog to Android.mk can solve my isuue. This is because the __android_log_print is defined in libLog

    0 讨论(0)
  • 2020-12-02 10:15

    We can link a shared library in Android in 3 ways. In below 3 cases, the lines mentioned should be added in Android.mk

    So here are the three ways.

    1. LOCAL_LDLIBS way
    LOCAL_LDLIBS := -llog
    

    For some reason if 1 doesnt work(it did not work for me), You can try below 2 ways

    2. LOCAL_LDFLAGS way
    LOCAL_LDFLAGS := -llog
    
    3. LOCAL_SHARED_LIBRARIES way
    LOCAL_SHARED_LIBRARIES += liblog
    

    Of course you also need to include #include <android/log.h> in your C/H file.

    0 讨论(0)
提交回复
热议问题