VS2012中使用Boost库的方法(超级简单)

很不错的博客一定得看

http://my.csdn.net/caimouse

1、下载boost库

从http://www.boost.org上下载到目前最新的boost库,快速传送门:boost_1_53_0.zip,当然你也可以从http://sourceforge.net/projects/boost/files/boost-jam/这里得到源代码,快速传送门:boost_1_53_0.zip(98.1 MB)

 

我使用了后者


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="F:oostoost_1_53_0invc11" link=static runtime-link=shared runtime-link=static threading=multi debug release


 

稍微等一会,库就编译好了……


5、开始使用boost


首先需要设定文件包含目录:

我的boost库解压在F盘下




设定库目录:




“F:oostoost_1_53_0”是我编译的出来lib的目录


然后建立我们的第一个boost项目,代码如下:


  1. #include "stdafx.h"  
  2. #include "boost/thread.hpp"  
  3. #include "iostream"  
  4. using namespace std;  
  5.   
  6. void mythread()  
  7. {  
  8.     cout << " hello,thread! " << endl;  
  9. }  
  10.   
  11. int _tmain(int argc, _TCHAR* argv[])  
  12. {  
  13.     boost::function<void()> f(mythread);  
  14.     boost::thread t(f);  
  15.     t.join();  
  16.     cout << " thread is over! " << endl;  
  17.   
  18.   
  19.     return 0;  
  20. }  


6.这是输出:



原文地址:https://www.cnblogs.com/lchb/p/3449408.html