vs2019配置c++ boost库
前言
安装编译Boost c++ library
环境
vs2019
boost 1.77.0
过程
一.安装Boost库
去官网进行下载:
https://www.boost.org/
我当前下载的版本是1.77.0
下载完成后解压到自己指定的目录
然后打开命令行编译工具
Cd 到解压好的boost目录
然后运行目录下的bootstrap.bat
完成后会在目录下生成一个b2.exe
使用 .\b2 --help 查看编译选项
根据需求选择,这里不一一列出来
我这里用的参数为
b2.exe --toolset=msvc-14.1 architecture=x86 address-model=64 link=static --build-type=complete --with-system --with-thread --with-date_time --with-filesystem --with-serialization
注意
1.MSVC 版本号对应
2.vs2019 可以支持boost c++ library 针对msvc-14.1的编译选项
稍等即可编译完成,完成后输出如下
两个路径会在使用Boost库时工程属性中包含目录和库目录中用到
新建vs2019 c++项目,并添加boost依赖库
点击菜单栏 项目——>属性——>选择VC++目录,在包含目录 和 库目录添加以上2个路径,如下图:
也可以新建一个系统环境变量BOOST_DIR
,值为C:\program\boost_1_70_0
。
在path系统环境变量中添加:%BOOST_DIR%
;
VC++包含目录中添加: %BOOST_DIR%
;
VC++库目录中添加: %BOOST_DIR%\stage\lib
;
代码测试:
#include <boost/lexical_cast.hpp>
#include <iostream>
using namespace std;
using namespace boost;
int main()
{
//system("chcp 65001");
double a = lexical_cast<double>("3.1415926");
string str = lexical_cast<string>("3.1415926");
cout << "This is a number: " << a << endl;
cout << "This is a string: " << str << endl;
int b = 0;
try {
b = lexical_cast<int>("neo");
}
catch (bad_lexical_cast& e) {
cout << e.what() << endl;
}
return 0;
}
编译运行 输出:
可以正常使用boost库了