visual studio配置boost库

boost库的安装

前文介绍过boost库的安装,这里再次介绍一遍。
先去官网下载boost库最新版本

https://www.boost.org/users/download/
选择windows版本下载,zip和7z格式的都可以
https://cdn.llfc.club/1675230057233.jpg
解压后文件夹下有个一个bootstrap.bat文件,双击运行会生成b2.exe
https://cdn.llfc.club/1675231068369.jpg
然后在boost文件夹下启动cmd,执行 “.\b2.exe toolset=gcc”
https://cdn.llfc.club/1675231439687.jpg
编译时间和机器性能有关,执行编译过后,会在stage文件夹下生成lib文件夹,里面就是我们要用到的lib库。
https://cdn.llfc.club/1675232553339.jpg

visual配置boost

有两种方式使用boost库,一种是配置在项目工程里,一种是配置在环境变量里,推荐配置环境变量的方式使用boost库。
这里先介绍项目中配置
我的boost库目录在D:\cppsoft\boost_1_81_0
https://cdn.llfc.club/1675914582118.jpg
打开visualstudio 创建一个控制台工程,然后右键工程选择属性
选择VC++目录—》包含目录,添加 D:\cppsoft\boost_1_81_0;
选择VC++目录—》库目录,添加 D:\cppsoft\boost_1_81_0\stage\lib;
https://cdn.llfc.club/1675914930021.jpg
然后我们写一段代码测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
#include "boost/lexical_cast.hpp"
int main()
{
using namespace std;
cout << "Enter your weight: ";
float weight;
cin >> weight;
string gain = "A 10% increase raises ";
string wt = boost::lexical_cast<string> (weight);
gain = gain + wt + " to "; // string operator()
weight = 1.1 * weight;
gain = gain + boost::lexical_cast<string>(weight) + ".";
cout << gain << endl;
system("pause");
return 0;
}

我们运行程序可以看到运行成功了,并且弹出了窗口
https://cdn.llfc.club/1675233803676.jpg