问题描述
我想使用这个 CmakeLists.txt 片段导入一个预构建的库:
I want to import a prebuilt library using this CmakeLists.txt snippet:
add_library(openssl-crypto
SHARED
IMPORTED )
set_target_properties(openssl-crypto
PROPERTIES
IMPORTED_LOCATION
${external_DIR}/libs/${ANDROID_ABI}/libcrypto.so )
include_directories(${external_DIR}/include/openssl)
我将此链接到我的图书馆:
I linked this to my library as:
target_link_libraries(aes-crypto openssl-crypto)
尝试构建会返回此错误:
Attempting to build returns this error:
'/libs/arm64-v8a/libcrypto.so', needed by ..., missing and no known rule to make it
推荐答案
我发现 IMPORTED_LOCATION
属性在传递给 set_target_properties
函数时不喜欢相对路径.
I found that the IMPORTED_LOCATION
property, when passed to the set_target_properties
function doesn't like relative paths.
来自 IMPORTED_LOCATION 上的 CMake 文档强>
导入目标的磁盘上主文件的完整路径.
为了解决这个问题,我使用了库的完整路径.
To resolve this issue, I used the full path to the library instead.
示例:
set_target_properties ( curl-lib
PROPERTIES IMPORTED_LOCATION
libs/${ANDROID_ABI}/libcurl.a )
. . . becomes . . .
set_target_properties ( curl-lib
PROPERTIES IMPORTED_LOCATION
${PROJECT_SOURCE_DIR}/src/main/cpp/libs/${ANDROID_ABI}/libcurl.a )
图书馆的路径可能与上面的略有不同,但 ${PROJECT_SOURCE_DIR}
通常是一个很好的起点,因为它被定义为:
The path to the library may differ slightly for you from the one above, but ${PROJECT_SOURCE_DIR}
is normally a good starting point as it is defined as:
...在当前目录范围或其父目录之一中对 project() 命令的最后一次调用的源目录.请注意,它不受在子目录范围内(即从当前范围对 add_subdirectory() 的调用)调用 project() 的影响.
这篇关于cmake:当我导入预建库时,缺少并且没有已知的规则来制作它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!