AndreaDO

导航

windows-vs2022-配置boost开发

windows-vs2022-配置boost开发

1.先去官网下载boost库最新版本

https://www.boost.org/users/download/
选择windows版本下载,zip和7z格式的都可以
image

2.下载解压后点击bootstrap.bat文件,双击运行会生成b2.exe

image

然后输入下述命令进行编译,编译时间会比较长,分别针对的是32位和64位,prefix是你想要编译后放在什么地方

b2.exe install --prefix="E:/Boost/x64" --build-type=complete --toolset=msvc-14.3 threading=multi --build-type=complete address-model=64

b2.exe install --prefix="E:/Boost/x86" --build-type=complete --toolset=msvc-14.3 threading=multi --build-type=complete address-model=32

编译时间有点长,慢慢等一会就好

3.去vs2022里右键项目的属性

如图平台工具集后(v143)就是14.3
image

在VC++目录中修改这两处:包含目录库目录

包含目录是你boost解压后的主目录
image

库目录是你编译后的目录
image
这两处修改完成后就基本上没事了

4.编写代码测试

#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;
}

可以正常输出运行,我们这里就配置结束了
image

posted on 2024-03-24 08:21  AndreaDO  阅读(1917)  评论(0)    收藏  举报