编译并使用boost库(win7+boost1.60+vs2013)

来源:互联网 发布:nginx转发配置 编辑:程序博客网 时间:2024/05/16 08:23
下载boost库

从http://www.boost.org上下载到目前最新的boost库,快速传送门:boost_1_60_0.zip

 

得到源代码之后,使用vs2013的cl.exe编译




进入到源代码目录中


建立编译工具bjam.exe----需要执行bootstrap.bat



指定编译命令

 

指定msvc版本12.0对应的是vs2013--stagedir是指定编译后存放的目录

[cpp] view plain copy
print?
  1. bjam stage --toolset=msvc-12.0 --without-graph --without-graph_parallel --stagedir="D:\boost\boost_1_60_0\bin\vc12" link=static runtime-link=shared runtime-link=static threading=multi debug release  

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


开始使用boost

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

我的boost库解压在D盘下


设定库目录:


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

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

这是输出

原创粉丝点击