Boost安装配置错误整理,踩过的坑(vs2013+boost1.73.0)

这篇博客详细记录了在Windows环境下,使用VS2013和Boost1.73.0安装过程中遇到的错误及其解决方案,包括运行bootstrap.bat时的命令行错误、编译boost库缺少lib文件的问题以及VS2013内部编译错误。通过设置环境变量、正确配置b2.exe参数和更新VS2013到Update5,成功完成Boost的安装和配置。

Boost安装错误整理

最新的boost是Version 1.73.0,官网下载:https://www.boost.org/users/download/#history

一、运行bootstrap.bat批处理文件时报错

:Failed to build Boost.Build engine.:
cl’ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
在这里插入图片描述

解决方案:

  1. 设置系统环境变量 Path = C:\Windows\System32,重启电脑生效!
  2. 在VS2013的工具集找到x86命令行工具(估计因为boost版本都是32位的),cd到boots的目录,再输入.\bootstrap.bat msvc ,编译运行OK。
    在这里插入图片描述

二、得到b2.exe程序和bjam.exe(我安装的最新boost_1_73_0编译后只有b2.exe,其实这两个exe一样的,问题不大)

注意:使用这个工具来编译boost库,VS2013要指定输出库的类型,否则会缺少一个lib文件。我这里是缺少了thred的一个lib文件,后面编译boostTest工程报错。
// 如果要获取动态库:
b2 install stage --toolset=msvc-12.0 --stagedir=”C:\Boost\boost_vc_120” link=shared runtime-link=shared threading=multi debug release
// 如果是要获取静态库:项目属性的代码生成要对应的改为多线程调试/MTD
b2 install stage --toolset=msvc-12.0 --stagedir=”C:\Boost\boost_vc_120” link=static runtime-link=static threading=multi debug release
//生成64位的boost库**
b2 install stage --toolset=msvc-12.0 architecture=x86 address-model=64 --without-graph --without-graph_parallel --stagedir=“D:\boost\boost_1_73-x64” link=static runtime-link=shared runtime-link=static threading=multi debug release
其中msvc 后的12.0或者13.0等,表示VS2013和VS2014等。
然后编译,大概需要半个小时,看PC配置如何。
参考博客:https://blog.youkuaiyun.com/qq_31098037/article/details/72716734
编译boost好后是这样子的:
在这里插入图片描述

之后在项目属性里,编译链接到对应的boost/include 和lib文件夹即可。
如:上面编译输出到C盘的C:\Boost\include\boost-1_73 和C:\Boost\lib,当然也可以移到其他位置。
在这里插入图片描述
在这里插入图片描述

三、莫名的内部编译错误:vs2013的bug,更新到update5即可。

又有问题(抓狂!):内部编译错误,听说是人品错误。。
下载VS2013 update5的更新包,将VS2013版本更新到update5即可:
链接:https://pan.baidu.com/s/1upX4SNSomZy4rnAY-LMMTA
提取码:wngl
直接下载就好,会检测你的电脑有没有VS2013的。

最后终于OK啦,花费近一个上午啊,做个记录吧,也希望能帮助到大家。
剽窃的测试用例:

#include <iostream>
#include <boost/thread/thread.hpp>
#include <boost/lexical_cast.hpp>
using namespace std;
void hello()
{
	cout<< "Hello world, I'm a thread!" << endl;
}
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;
	}
	boost::thread thrd(&hello);
	thrd.join();
	return 0;
}

参考:https://blog.youkuaiyun.com/rocklee/article/details/72885587
boost使用线程池的例子:https://blog.youkuaiyun.com/zengraoli/article/details/70187693

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值