引言
最近想要了解一下C++的Boost
库,于是记录下配置Boost
库的全过程。平台为Windows10,版本为1803,所使用到的编译器为MinGW64以及VS17。
配置步骤
下载源码
官网地址: https://www.boost.org 传送门
下载对应的版本,此时的最新版本为1.69
解压
现在完成后进行解压,然后进入解压后的文件夹
编译
双击文件夹的路径地址栏
然后输入cmd
后回车
进入命令行界面后输入bootstrap.bat
进行预编译生成编译程序
预编译完成后会生成两个编译程序(见下图),输入.\b2.exe
进行编译,此过程较长需要大约半小时左右。
引入Boost
编译完成后生成的库文件在boost_1_69_0\stage\lib
文件夹下,所需的头文件在boost_1_69_0\boost
下。
在VS17中新建名为boostest
的控制台应用程序并添加boostest
工程的包含目录(include头文件)和库目录(lib库文件):
工程名->配置属性->c/c++>常规->附加包含目录,添加: D:\path\to\boost_1_67_0
工程名->配置属性->链接器->常规->附加库目录,添加: D:\path\to\boost_1_67_0\stage\lib
测试代码
#include "pch.h"
#include <iostream>
#include <boost/lexical_cast.hpp>
using namespace std;
int main()
{
using boost::lexical_cast;
int a = lexical_cast<int>("123");
double b = lexical_cast<double>("123.0123456789");
string s0 = lexical_cast<string>(a);
string s1 = lexical_cast<string>(b);
cout << "number: " << a << " " << b << endl;
cout << "string: " << s0 << " " << s1 << endl;
int c = 0;
try {
c = lexical_cast<int>("abcd");
}
catch (boost::bad_lexical_cast& e) {
cout << e.what() << endl;
}
}
本文由 giao创作, 采用 知识共享署名4.0 国际许可协议进行许可 本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名 原文地址:《win10下C++ Boost库配置》
最后一次更新于2019-04-04
路过 学习了
By vultr at April 8th, 2019 at 01:13 pm.
@vultr
感谢支持!
By kivii at April 8th, 2019 at 03:03 pm.