以前在linux下装过Boost,但是介于自己目前最常用的开发平台还是windows,所以查了下怎么在windows下安装并使用Boost(只是mark了别人的博客放自己这里方便自己查找);
推荐个学习Boost的网站 http://zh.highscore.de/cpp/boost/
1、下载boost库
从http://www.boost.org上下载到目前最新的boost库,快速传送门:Boost_1_67_0
2、得到源代码之后,使用vs2012的cl.exe编译
进入到源代码目录中
3、建立编译工具bjam.exe----需要执行bootstrap.bat
4、指定编译命令
指定msvc版本11.0对应的是vs2012,--stagedir是指定编译后存放的目录
bjam stage --toolset=msvc-11.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-python --without-serialization --without-wave --stagedir="D:\VS2012\boost_1_67_0\bin\vc11" link=static runtime-link=shared runtime-link=static threading=multi debug release
稍微等一会(其实还挺久的),库就编译好了……
5、开始使用boost
在vs2012上设置如下
然后开始使用吧!
下面是测试代码
#include "boost/thread.hpp"
#include "iostream"
using namespace std;
void mythread()
{
cout << " hello,thread! " << endl;
}
int main()
{
boost::function<void()> f(mythread);
boost::thread t(f);
t.join();
cout << " thread is over! " << endl;
return 0;
}
对了。编译完目录下的那个
bin.v2是个临时文件夹,(非常大 硬盘容量吃紧的就删掉吧!)