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:\boost\boost_1_53_0\bin\vc11" link=static runtime-link=shared runtime-link=static threading=multi debug release


 

稍微等一會,庫就編譯好了……


5、開始使用boost


首先需要設定文件包含目錄:

我的boost庫解壓在F盤下




設定庫目錄:




“F:\boost\boost_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.這是輸出:




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM