第一步在官网下载最新版的boost库文件

www.boost.org

当前最新版的是1.70;

window搭建boost库

window搭建boost库

下载完成后解压文件夹。建议放到C盘,因为这样不容易错误删除。

运行bootstrap.bat这个文件会出现

window搭建boost库

这两个文件,不运行时不出来的。

window搭建boost库

 

建议完全,完全安装的命令:这条命令可是生成的是静态链接库想要生成动态链接库需要加点东西

b2 --toolset=msvc-14.1 stage
 b2 --toolset=msvc-14.1 --stagdir=./stage/dll link=shared

 这是生成动态链接库的命令。

msvc这个是看你的编译器是哪个版本的,我在网上找到一个对比图

window搭建boost库

对号入座就好了。

环境配置:

新建一个C++工程弄成X64的

window搭建boost库

配置环境,进入项目属性。

window搭建boost库

添加目录:这个放的是你boost库实际的存放位置。

window搭建boost库

比如我的是C:\local\boost\boost_1_70_0\boost_1_70_0

window搭建boost库

然后:

 window搭建boost库

链接文件就是之前编译的文件目录。

 

测试文件:

网上找的一个demo

#include <boost/lexical_cast.hpp>       
#include <iostream>

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

	return 0;
}

window搭建boost库

测试结果:

window搭建boost库

相关文章: