使用CMake链接Boost库的静态版本 [英] Link the static versions of the Boost libraries using CMake
问题描述
我在/usr/lib中拥有了boost库的静态和动态版本.现在,我希望CMake在可执行文件链接期间更喜欢静态版本.我该怎么办?
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. What can I do?
推荐答案
在您的CMakeLists.txt
文件中:
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED ...)
在我有...
的位置,您可以选择放置要使用的库的名称,然后在下面放置target_link_libraries(targetname ${Boost_LIBRARIES})
.如果您有较新的CMake发行版,则应完全按照广告宣传的方式运行.我正是在自己的项目中以这种方式进行操作.
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.
这篇关于使用CMake链接Boost库的静态版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!