以前配置过vs2010+boost_1_49_0,现在安装vs2012了,所以得重新编译配置,而且boost的版本也有更新。
首先下载boost,这个可以再官网上下载,http://www.boost.org,下载后,解压保存在你要编译的硬盘下,最后编译的文件就要保存在解压的这个文件下。
然后进行编译,打开vs2012的本地工具 (vs2012 x86 Native Tools Command Prompt)
转到解压的boost的目录,执行bootstrap.bat ,以建立编译工具bjam.exe 。
然后在进行编译执行:
指定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="F:\boost\boost_1_53_0\bin\vc11" link=static runtime-link=shared runtime-link=static threading=multi debug release
约需要半个小时,编译完成。
最后 开始使用boost。
首先需要设定文件包含目录:
我的boost库解压在F盘下
设定库目录:
“F:\boost\boost_1_53_0\”是我编译的出来lib的目录
然后建立我们的第一个boost项目,代码如下:
- #include "stdafx.h"
- #include "boost/thread.hpp"
- #include "iostream"
- using namespace std;
- void mythread()
- {
- cout << " hello,thread! " << endl;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- boost::function<void()> f(mythread);
- boost::thread t(f);
- t.join();
- cout << " thread is over! " << endl;
- return 0;
- }
这是输出: