cmake doesn't support imported libraries?

后端 未结 2 1738
后悔当初
后悔当初 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)
    

提交回复
热议问题