为什么Android NDK log.h __android_log_print链接错误

why Android NDK log.h __android_log_print linker error

本文关键字:log print 链接 错误 android Android NDK 为什么      更新时间:2023-10-16

我尝试使用__android_log_print。但是出现了链接错误。我使用了makefile Android。可:-

    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_SRC_FILES := com_test_JniTest.cpp
    LOCAL_MODULE := com_test_JniTest
    LOCAL_LDLIBS += -llog
    include $(BUILD_SHARED_LIBRARY)

我得到错误:-

/用户/abc/AndroidStudioProjects/测试/app/src/main/jni/com_test_JniTest.cpp错误:(29)未定义对' __android_log_print'的引用

如何链接和使用__android_log_print ?

可能是路径的问题。

搜索liblog的路径。所以在你的系统中设置如下:

LOCAL_LDLIBS := -L<path to liblog.so> -llog
例如:

LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog

或者如果你使用Gradle,你必须在build.gradle

中指定lib
android {
    defaultConfig {
        ndk {
            moduleName "whatever"
            ldLibs "log"
        }
    }
}