我正在尝试链接一个预编译的共享库文件,名为libtest-lib.so。以下是CMakeLists.txt底部的内容:
link_directories("/projectspath/LinkTest/TestLib/app/build/intermediates/cmake/debug/obj/armeabi-v7a")
add_library(testlib libtest-lib.so)
target_link_libraries(testlib libtest-lib.so)
就像上面一样,我得到了以下错误:
CMake Error at CMakeLists.txt:49 (add_library):
Cannot find source file:
libtest-lib.so
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
CMake Error: CMake can not determine linker language for target: testlib
如果我注释掉add_library这一行,就会出现以下情况:
CMake Error at CMakeLists.txt:51 (target_link_libraries):
Cannot specify link libraries for target "testlib" which is not built by this project.
看起来在链接库时绝对需要源文件(.c,cpp等)。但是我如何链接 .so 文件呢?文档中关于 target_link_libraries() 给出了以下说明:
所命名的 library 必须已由诸如 add_executable() 或 add_library() 等命令在当前目录中创建。
如果我将 add_library() 替换为 add_executable(),我会得到相同的错误。在 CMake 中链接 .so 文件的正确方式是什么?