我需要在我的CMakeLists.txt中添加Boost库。你是怎么做的,还是怎么添加的?
发布于 2011-07-11 14:31:59
将其放入您的CMakeLists.txt
文件中(如果需要,可以将任何选项从OFF更改为ON ):
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*
的地方。例如,如果你使用的是filesystem
和regex
库,你可以这样写:
find_package(Boost 1.45.0 COMPONENTS filesystem regex)
发布于 2017-05-10 15:04:44
将@LainIwakura的答案改写为具有导入目标的现代CMake语法,这将是:
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.45.0 COMPONENTS filesystem regex)
if(Boost_FOUND)
add_executable(progname file1.cxx file2.cxx)
target_link_libraries(progname Boost::filesystem Boost::regex)
endif()
请注意,不再需要手动指定包含目录,因为它已经通过导入的目标Boost::filesystem
和Boost::regex
进行了处理。
您需要的任何boost库都可以替换为regex
和filesystem
。
发布于 2018-09-06 20:57:31
set(Boost_USE_STATIC_LIBS ON) # only find static libs
set(Boost_USE_DEBUG_LIBS OFF) # ignore debug libs and
set(Boost_USE_RELEASE_LIBS ON) # only find release libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.66.0 COMPONENTS date_time filesystem system ...)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(foo foo.cc)
target_link_libraries(foo ${Boost_LIBRARIES})
endif()
不要忘记将foo替换为您的项目名称,将组件替换为您的项目名称!
https://stackoverflow.com/questions/6646405
复制相似问题