How to add prebuilt static library in project using CMake?

后端 未结 4 470
粉色の甜心
粉色の甜心 2020-12-11 15:59

Clion: how add or (use) prebuilt static library in my Project?

4条回答
  •  粉色の甜心
    2020-12-11 16:08

    I've linked my static lib test.a with the related header files as following:

    Project
    ├── main.cpp
    ├── CmakeLists.txt
    ├── libs
    │   ├── includes
    │   │   ├── *.h
    │   ├── lib
    │   │   ├── test.a
    

    I've added this to the ./CMakeLists.txt:

    include_directories(${CMAKE_SOURCE_DIR}/libs/include)
    find_library(Test_LIB test "${CMAKE_SOURCE_DIR}/libs/lib")
    add_executable(TestApp main.cpp)
    target_link_libraries(TestApp ${Test_LIB})
    

    By adding message(${Test_LIB}), you can print out and check the path.

提交回复
热议问题