我想使用CMake将Android上不同架构的预编译共享库链接到我自己的jni共享库。
我正在尝试使用target_link_libraries
命令。
这是我的CMake文件:
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_C_STANDARD 99)
set (CMAKE_CXX_STANDARD 11)
add_library( # Sets the name of the library.
python-algo-jni
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
jni.cpp )
set_target_properties(python-algo-jni PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(python-algo-jni libs/${ANDROID_ABI}/libpython3.5m.so)
当我尝试构建时,我收到此错误:
Execution failed for task ':calmnessscore:externalNativeBuildDebug'.
> Build command failed.
Error while executing process /Users/mac/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/mac/Projects/PythonAlgorithmAndroid/calmnessscore/.externalNativeBuild/cmake/debug/x86_64 --target python-algo-jni}
[1/2] Building CXX object CMakeFiles/python-algo-jni.dir/jni.cpp.o
[2/2] Linking CXX shared library /Users/mac/Projects/PythonAlgorithmAndroid/calmnessscore/build/intermediates/cmake/debug/obj/x86_64/libpython-algo-jni.so
FAILED: : && /Users/mac/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=x86_64-none-linux-android --gcc-toolchain=/Users/mac/Library/Android/sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/mac/Library/Android/sdk/ndk-bundle/sysroot -fPIC -isystem /Users/mac/Library/Android/sdk/ndk-bundle/sysroot/usr/include/x86_64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a --sysroot /Users/mac/Library/Android/sdk/ndk-bundle/platforms/android-21/arch-x86_64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libpython-algo-jni.so -o /Users/mac/Projects/PythonAlgorithmAndroid/calmnessscore/build/intermediates/cmake/debug/obj/x86_64/libpython-algo-jni.so CMakeFiles/python-algo-jni.dir/jni.cpp.o -llibs/x86_64/libpython3.5m.so -lm "/Users/mac/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/libgnustl_static.a" && :
/Users/mac/Library/Android/sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/darwin-x86_64/lib/gcc/x86_64-linux-android/4.9.x/../../../../x86_64-linux-android/bin/ld: error: cannot find -llibs/x86_64/libpython3.5m.so
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
但图书馆确实存在。
答案 0 :(得分:0)
我找到了解决方案:只需将${CMAKE_CURRENT_SOURCE_DIR}/
添加到lib路径
target_link_libraries(python-algo-jni ${CMAKE_CURRENT_SOURCE_DIR}/libs/${ANDROID_ABI}/libpython3.5m.so)