a這個可行
http://jingyan.baidu.com/article/00a07f3843a33e82d028dcbf.html
最近打算學習一下Boost庫,這裡記錄一下Boost庫的安裝的方法。 方法/步驟
下載:
先到Boost官方網上下載原始碼。
編譯VS2008版本的Boost庫:
首先,編譯bjam,在命令列下,運行bootstrap.bat -vc9,然後,編譯庫。
編譯動態庫:bjam stage --toolset=msvc-9.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-python --without-serialization --without-wave --stagedir="D:\Boost\bin\vc9" link=static runtime-link=shared threading=multi debug release
編譯靜態庫:bjam stage --toolset=msvc-9.0 --without-graph --without-graph_parallel --without-math --without-mpi --without-python --without-serialization --without-wave --stagedir="D:\Boost\bin\vc9" link=static runtime-link=static threading=multi debug release
編譯用了15分鐘左右,產生了303MB左右的檔案
VS2008 Boost庫配置:
Tools -> Options -> Projects and Solutions -> VC++ Directories 在Library files中,增加D:\Boost\bin\vc9\lib在Include files中,增加D:\Boost\其中,Library的目錄就是前面編譯產生的那些庫檔案儲存到的位置其中,Include的目錄隨著Boost的不同版本會不同,現在1.47版本只要指定為D:\Boost即使用SVN下載Boost的檔案夾就可以了。
VS2008 Boost庫測試:
#include "stdafx.h"
#include <iostream>
#include <boost/date_time/gregorian/gregorian.hpp>
using namespace std;
using namespace boost;
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"請輸入您的生日,格式\"YYYY-MM-DD\":";
string strBirthday;
cin>>strBirthday;
try
{
gregorian::date birthday( gregorian::from_simple_string(strBirthday) );
gregorian::date today( gregorian::day_clock::local_day() );
gregorian::days days_alive = today - birthday;
if( days_alive < gregorian::days(0) )
{
cout<<"哇,還沒出生就能用電腦了,真厲害"<<endl;
}
else
{
cout<<"您在這個世界上出現了:"<< days_alive.days()<< "天了" << endl;
}
}
catch( gregorian::bad_year& e )
{
cerr<< e.what() << endl;
}
catch( gregorian::bad_day_of_month& e )
{
cerr<< e.what() << endl;
}
catch( gregorian::bad_day_of_year& e )
{
cerr<< e.what() << endl;
}
catch(...)
{
cerr<<"Error!"<<endl;
}
system( "pause" );
return 0;
}