NDK开发 error: undefined reference to '__android_log_print'

修改部分:

1、build.gradle(:app)

ndk {
                ldLibs "log"//实现__android_log_print
                abiFilters "armeabi-v7a", "x86", "x86_64", "arm64-v8a"
            }

如果报错:abis [armeabi] are not supported for platform. supported abis are [arm64-v8a, armeabi-v7a, x86, x86_
需要把abiFilters 后面的"armeabi"去掉,或者直接注释到abiFilters

2、修改CMakeLists.txt

目前自动生成的CMakeLists都带有以下代码,如果没有需要添加

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log )
target_link_libraries( # Specifies the target library.
        native-lib

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib} )

特别注意!

如果生成不止一个文件(包括so文件和可运行文件!),需要每个文件都链接

target_link_libraries( # Specifies the target library.
        native-lib

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib} )

target_link_libraries( # Specifies the target library.
        testcam

        # Links the target library to the log library
        # included in the NDK.
        ${log-lib} )
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容