cmake:missing and no known rule to make it when I

2019-02-06 00:28发布

问题:

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

回答1:

I found that 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 )



回答2:

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.



标签: cmake