Android ndk(cmake):在第二个 jni 库中使用 log api 时,'未定义的引用`__android_log_write'
问题描述
我使用 Android Studio 2.2 和 cmake 构建 jni 文件.
I use Android Studio 2.2 and cmake to build jni file.
我想在 jni 文件中显示日志,但收到错误消息未定义对 `__android_log_write 的引用".
I want to show log in jni file but get error message "undefined reference to `__android_log_write".
我的 CMakeLists.txt 文件是:
My CMakeLists.txt file is :
我的两个jni文件和下面一样,没有函数名
And my two jni files are the same as below without function name
我的 build.gradle(Module:app) 是
My build.gradle(Module:app) is
根据 android 文档:将 C 和 C++ 代码添加到您的项目.我想我可以使用日志 api.
According to the android document:Add C and C++ Code to Your Project. I think I can use log api.
我的代码或设置有什么问题?
What's wrong in my code or my setting ?
更新:
我发现在我的第一个 jni 库中没有问题(更新代码).
I found it is not problem in my first jni library(Update code).
它只在第二个库中发生错误.
It only occurs error in the second library.
ex: target_link_libraries(test-lib, native-lib, ...),native-lib 是要加载的第二个库.
ex: target_link_libraries(test-lib, native-lib, ...), native-lib is the second library to be loaded.
所以 native-lib 不能使用 log api.
So native-lib can't use log api.
现在我唯一能做的就是删除native-lib.但是我真的很想知道为什么?
Now I only can do is to remove native-lib. However I really want to know why ?
推荐答案
我终于发现我应该分开做链接了.
I finally found I should separated to do the link.
这篇关于Android ndk(cmake):在第二个 jni 库中使用 log api 时,'未定义的引用`__android_log_write'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!