Windows下下载编译boost库

下载boost库

链接:https://www.boost.org/

image-20240802082512083

下载最新的版本即可,因为最新的版本是兼容以前版本的。

编译boost库

下载后解压

image-20240802082746860

如果没有b2.exe就先双击一下booststrap.bat自动生成文件。然后在此目录打开cmd;

执行命令:

.\b2.exe install --toolset=msvc-14.3 --build-type=complete --prefix="D:\cppsoft\boost_1_81_0" link=static runtime-link=shared threading=multi debug release

image-20240802083020385

msvc-14.3是vs2022对应的版本,如果你的不是vs2022请百度对应的msvc版本进行相应修改,如vs2019对应的是14.2,注意只需14.2即可,不用再精细到14.22、14.23这样。prefix后面是安装路径请自行更改。按下回车等待20分钟左右编译时间。

编译完成后进入选择的路径如下:

image-20240802083654330

这样就是成功了。

配置boost库

打开vs2022创建新项目:

image-20240802083546502

创建控制台应用:

image-20240802083739613

打开视图,找到属性管理器:

image-20240802083831879

添加新项目属性表:

image-20240802083908463

直接点击添加:

image-20240802083929172

打开刚才添加的属性表并选择VC++目录:

image-20240802084004510

image-20240802084131614

配置boost头文件和lib文件,分布是图中包含目录和库目录,注意层级关系:

image-20240802084252209

image-20240802084307886

然后测试:

#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-20240802084347526

posted @ 2024-08-02 08:51  桂洛克船长  阅读(2)  评论(0编辑  收藏  举报