Link the static versions of the Boost libraries using CMake

前端 未结 2 1617
醉话见心
醉话见心 2021-01-30 13:44

I\'ve got both the static and the dynamic versions of the boost libraries in /usr/lib. Now I\'d like CMake to prefer the static versions during the linkage of my executable. Wha

2条回答
  •  日久生厌
    2021-01-30 14:13

    In your CMakeLists.txt file:

    set(Boost_USE_STATIC_LIBS   ON)
    find_package(Boost REQUIRED ...)
    

    Where I have ..., you optionally put the names of the libraries you want to use, and then target_link_libraries(targetname ${Boost_LIBRARIES}) later below. If you have a fairly recent distribution of CMake, it should work exactly as advertised. I do it exactly this way in my own projects.

提交回复
热议问题