在Windows下Boost庫編譯方法與測試

來源:互聯網
上載者:User

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;

}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.