在Windows下Boost库编译方法与测试

a这个可行

http://jingyan.baidu.com/article/00a07f3843a33e82d028dcbf.html


最近打算学习一下Boost库,这里记录一下Boost库的安装的方法。

方法/步骤

  1. 下载:

    先到Boost官方网上下载源代码。

  2. 编译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左右的文件

  3. 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的文件夹就可以了。

  4. 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;

    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值