26

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
7
  • 1
    What if you use: add_dependencies(aes-crypto openssl-crypto) Does that help? And how do you build openssl-crypto?
    – fedepad
    Jan 5, 2017 at 8:31
  • The add_dependencies did not work. I used the add_library(openssl-crypto SHARED IMPORTED) to build the openssl-crypto library Jan 6, 2017 at 1:51
  • 1
    The problem seems to be that the variable "external_DIR" is empty. Jan 6, 2017 at 9:56
  • Thank you. The external_DIR is empty,actually, I do not see the same error when I change external_DIR to the absolute path. But now I encounter a new error which is "error adding symbols: File in wrong format" when I build another prebuilt library like add_library(jni-native-helper SHARED IMPORTED) set_target_properties(jni-native-helper PROPERTIES IMPORTED_LOCATION ../../../../src/main/cpp/external/libs/arm64-v8a/libnativehelper.so:), Jan 9, 2017 at 10:01
  • 1
    @user7377570 you should create a new question for it. I'm running into the same issues you are.
    – Nathan F.
    Jun 7, 2017 at 22:15

3 Answers 3

30

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).

0
3

You can use set_property function with attribute TARGET instead of set_target_properties, and then you can set path relatively using macros ${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 ) 

Maybe you can use macros ${PROJECT_SOURCE_DIR} while set lib path with set_target_properties but I didn't check this way.

1
  • Using ${PROJECT_SOURCE_DIR} when set lib path with set_target_properties works for me. This answer should be accepted
    – Marvin
    Sep 6, 2017 at 5:53
0

Maybe file have wrong datetime. Set current datetime for ${external_DIR}/libs/${ANDROID_ABI}/libcrypto.so:

touch ${external_DIR}/libs/${ANDROID_ABI}/libcrypto.so

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.