cmake:missing and no known rule to make it when I import a prebuilt library

后端 未结 3 1793
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 16:57

I want to import a prebuilt library using this CmakeLists.txt snippet:

add_library(openssl-crypto
            SHARED
            IMPORTED )
set_target_proper         


        
相关标签:
3条回答
  • 2020-12-14 17:39

    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.

    0 讨论(0)
  • 2020-12-14 17:40

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

    touch ${external_DIR}/libs/${ANDROID_ABI}/libcrypto.so
    
    0 讨论(0)
  • 2020-12-14 17:44

    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 )
    

    0 讨论(0)
提交回复
热议问题