我想使用此CmakeLists.txt片段导入预建库:
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)
我将此链接到我的库:
target_link_libraries(aes-crypto openssl-crypto)
尝试构建会返回此错误:
'/libs/arm64-v8a/libcrypto.so', needed by ..., missing and no known rule to make it
答案 0 :(得分:21)
我发现set_target_properties
函数不喜欢相对路径。
来自CMake Documentation on IMPORTED_LOCATION
磁盘上主要文件的完整路径,用于IMPORTED目标。
要解决此问题,我使用了库的完整路径。
示例:
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 )
答案 1 :(得分:3)
您可以使用set_property
功能使用属性TARGET
代替set_target_properties
,然后您可以使用宏${PROJECT_SOURCE_DIR}
相对设置路径。
# import shared library libmylib.so
add_library( my-imported-lib
SHARED
IMPORTED)
# set the path to appropriate so files with appropriate architectures
set_property(TARGET
my-imported-lib
PROPERTY IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/<path_to_libs_directory>/${ANDROID_ABI}/libmy-imported-lib.so)
...
# link imported library to your developed library
target_link_libraries( my-developed-lib
my-imported-lib )
也许你可以在使用${PROJECT_SOURCE_DIR}
设置lib路径时使用宏set_target_properties
,但我没有这样检查。
答案 2 :(得分:0)
也许文件的日期时间错误。
设置${external_DIR}/libs/${ANDROID_ABI}/libcrypto.so
的当前日期时间:
touch ${external_DIR}/libs/${ANDROID_ABI}/libcrypto.so