轉載http://blog.csdn.net/isilent/article/details/7400359
1.下載boost
從http://www.boost.org/上下載boost庫,目前的版本是1.52
boost_1_52_0\ .................The “boost root directory” index.htm .........A copy of www.boost.org starts here boost\ .........................All Boost Header files libs\ ............Tests, .cpps, docs, etc., by library index.html ........Library documentation starts here algorithm\ any\ array\ …more libraries… status\ .........................Boost-wide test suite tools\ ...........Utilities, e.g. Boost.Build, quickbook, bcp more\ ..........................Policy documents, etc. doc\ ...............A subset of all Boost library docs
2.編譯
boost的一部分庫都是由hpp檔案組成,因此可以直接引用,而無需編譯。但也有一部分需要編譯成二進位代碼,為了今後方便,我們可以全部先編譯一遍。
1. 運行bootstrap.bat,完畢後會產生bjam.exe
2. 運行bjam.exe,
bjam.exe --toolset=msvc-9.0 --link=static --runtime-link=shared --threading=multi --without-python stage debug release
這時應該根據自己的需要考慮是否進行完全編譯,若完全編譯的話,簡單地執行命令 bjam --toolset=msvc-9.0 --build-type=complete 就可以了。(這裡用的是VC2010)
3.將boost添加到程式碼程式庫中boost目錄是標頭檔,stage\lib是靜態連結庫,根據需要拷貝到程式碼程式庫即可。如果只在本機上使用,也可以直接在VS中設定include和附加庫目錄。、輸出代碼
#include <boost/timer.hpp>#include <iostream>using namespace boost;using namespace std;int main(){timer t;cout << t.elapsed_max() / 3600 << "h" << endl;getchar();return 0;}