安装boost
从官网下载并解压到适当位置
Boost网站
在解压后的目录中找到
bootstrap.bat
点击运行,并等待结束
这时会出现b2.exe
文件,点击运行,耐心等待结束
(安装后产生的文件会占据大约4.3GB,请确保磁盘空间充足)
cmake 配置示例
文档地址
只寻找头文件
find_package(Boost 1.36.0)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(foo foo.cc)
endif()
寻找库文件并引入到目标文件中
find_package(Boost 1.56 REQUIRED COMPONENTS
date_time filesystem iostreams)
add_executable(foo foo.cc)
target_link_libraries(foo Boost::date_time Boost::filesystem
Boost::iostreams)
下面以引入Python模块作为示例,读者可仿照此例引入自己需要的模块。
寻找库“python3.6”并引入
find_package(Boost 1.67 REQUIRED COMPONENTS
python36 numpy36)
add_executable(foo foo.cc)
target_link_libraries(foo Boost::python36 Boost::numpy36)
寻找头文件和静态库文件并引入
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()
运行测试
项目配置
# CMakeLists.txt
cmake_minimum_required(VERSION 3.21)
project(test_0_1)
set(CMAKE_CXX_STANDARD 17)
set(Boost_INCLUDE_DIRS "D:/ProgramData/boost_1_78_0/" )
set(Boost_LIBRARIES "D:/ProgramData/boost_1_78_0/stage/lib")
include_directories(${Boost_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} main.cpp)
主程序
#include <boost/version.hpp>
#include <boost/config.hpp>
#include <iostream>
using namespace std;
int main()
{
cout << BOOST_VERSION << endl;
cout << BOOST_LIB_VERSION << endl;
cout << BOOST_PLATFORM << endl;
cout << BOOST_COMPILER << endl;
cout << BOOST_STDLIB << endl;
return 0;
}
输出:
107800
1_78
Win32
GNU C++ version 11.2.0
GNU libstdc++ version 20210728
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)