【发布时间】:2017-11-19 11:20:57
【问题描述】:
在以下来自 Google 教程的 sn-p 中“将 C 和 C++ 代码添加到您的项目”
在'添加其他预建库'部分中
add_library(...)
set_target_properties( # Specifies the target library.
imported-lib
# Specifies the parameter you want to define.
PROPERTIES IMPORTED_LOCATION
# Provides the path to the library you want to import.
imported-lib/src/${ANDROID_ABI}/libimported-lib.so )
来源:https://developer.android.com/studio/projects/add-native-code.html
与imported-lib/src/${ANDROID_ABI}/libimported-lib.so 关联的隐式根目录是什么?
我的第一个猜测是它是project/app/,即CMakeLists.txt 所在的目录,但实验表明情况并非如此。当我做出这个假设时,我收到链接错误,说找不到共享库中的函数。
更新:
在 Tsyvarev 的帮助下,我发现错误不是来自 set_target_properties(),而是来自 target_link_libraries()
set_target_properties() 似乎确实使用 project/app 作为其根
但target_link_libraries() 没有。如果我假设 project/app 是我预建共享库位置的根目录,那么我的项目构建将失败。如果我指定完整路径,即来自/home/me/...etc./etc./mylib.so,那么它确实有效。
第一个实例中的错误消息是:
/home/me/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: cannot find -llibs/armeabi-v7a/libmylib.so
也许这个实例中的根目录是ld 所在的目录?
【问题讨论】:
-
I get link errors saying the functions in the shared library cannot be found when I make this assumption.- 这个错误意味着你的共享库没有定义给定的函数。或者您忘记与该库链接(使用target_link_libraries)。如果链接器找不到要链接的库,则会发出 其他错误。
标签: android android-ndk cmake