cmake doesn't support imported libraries?

后端 未结 2 1703
后悔当初
后悔当初 2021-01-12 18:59

When I try to import a library using

 add_library(libname SHARED IMPORTED)
    set_property(TARGET libname PROPERTY IMPORTED_LOCATION //&l         


        
相关标签:
2条回答
  • 2021-01-12 19:25

    I was getting the same error as navderm when trying to import the Poco C++ libPocoFoundation.so library into my project, and after trying different solutions unsuccessfully, I managed to find one that worked for me:

    cmake_minimum_required(VERSION 3.5)
    project(MyProject)
    
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    
    add_library(PocoLib SHARED IMPORTED GLOBAL)
    
    # It's important to specify the full path to the library you want to import
    set_target_properties(PocoLib PROPERTIES IMPORTED_LOCATION "/usr/local/lib/Poco_1.7.2/lib/libPocoFoundation.so")
    
    # create my executable
    set(EXEC_SOURCE_FILES main.cpp)
    add_executable(MyProject ${EXEC_SOURCE_FILES})
    
    target_link_libraries(MyProject PocoLib)
    
    0 讨论(0)
  • 2021-01-12 19:27

    Cannot specify link libraries for target "libname" which is not built by this project

    When you use target_link_libraries to some target you're specifying how to build it, but imported library is already build. CMake told you that...

    Example of linking imported target to executable:

    add_library(boo SHARED IMPORTED)
    set_target_properties(boo PROPERTIES IMPORTED_LOCATION "/path/to/boo/library")
    add_executable(foo foo.cpp)
    target_link_libraries(foo boo)
    

    Note: using imported targets

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