歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 編譯並使用Boost庫(Win7+Boost1.53+VS2012)

編譯並使用Boost庫(Win7+Boost1.53+VS2012)

日期:2017/3/1 9:42:44   编辑:Linux編程

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)

我使用了後者

Boost程序庫完全開發指南——深入C++“准”標准庫高清PDF版 http://www.linuxidc.com/Linux/2013-07/87574.htm

Ubuntu下編譯安裝boost庫 http://www.linuxidc.com/Linux/2013-07/87573.htm

Ubuntu下編譯boost 1.52b http://www.linuxidc.com/Linux/2013-02/79004.htm

Ubuntu編譯安裝boost並在eclipse C/C++中使用 http://www.linuxidc.com/Linux/2011-04/34790.htm

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項目,代碼如下:

#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;
}

6.這是輸出:

Copyright © Linux教程網 All Rights Reserved