如何将 boost::program_options 添加到你的 CMake 构建中

只需将这些行添加到你的 CMakeLists.txt 末尾,并将 myTarget 替换为你的构建目标名称(通常是 add_executable(...)add_library(...) 的第一个参数):

add_boost_program_options.cmake
# 包含 boost
find_package( Boost 1.30 COMPONENTS program_options REQUIRED )
target_include_directories( myTarget PRIVATE ${Boost_INCLUDE_DIR})
target_link_libraries( myTarget ${Boost_LIBRARIES} )

如果你有多个目标,为每个目标复制并粘贴最后两行。

如果你需要特定版本的 boost,将 1.30 替换为你需要的最低版本。


Check out similar posts by category: Boost, C/C++, CMake