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
I found that the IMPORTED_LOCATION
property, when passed to the set_target_properties
function doesn't like relative paths.
From the CMake Documentation on IMPORTED_LOCATION
Full path to the main file on disk for an IMPORTED target.
To resolve this issue, I used the full path to the library instead.
Example:
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 )
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:
...the source directory of the last call to the project() command made in the current directory scope or one of its parents. Note, it is not affected by calls to project() made within a child directory scope (i.e. from within a call to add_subdirectory() from the current scope).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With