如何在 CMakeLists.txt 中添加 Boost 库? [英] How do you add Boost libraries in CMakeLists.txt?

查看:32
本文介绍了如何在 CMakeLists.txt 中添加 Boost 库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 Boost 库添加到我的 CMakeLists.txt 中.你是怎么做的或者你如何添加它?

I need to add Boost libraries into my CMakeLists.txt. How do you do it or how do you add it?

推荐答案

把它放在你的 CMakeLists.txt 文件中(如果你愿意,可以将任何选项从 OFF 更改为 ON):

Put this in your CMakeLists.txt file (change any options from OFF to ON if you want):

set(Boost_USE_STATIC_LIBS OFF) 
set(Boost_USE_MULTITHREADED ON)  
set(Boost_USE_STATIC_RUNTIME OFF) 
find_package(Boost 1.45.0 COMPONENTS *boost libraries here*) 

if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS}) 
    add_executable(progname file1.cxx file2.cxx) 
    target_link_libraries(progname ${Boost_LIBRARIES})
endif()

显然你需要把你想要的库放在我放*boost libraries here*的地方.例如,如果您正在使用 filesystemregex 库,您将编写:

Obviously you need to put the libraries you want where I put *boost libraries here*. For example, if you're using the filesystem and regex library you'd write:

find_package(Boost 1.45.0 COMPONENTS filesystem regex)

这篇关于如何在 CMakeLists.txt 中添加 Boost 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆