VC8编译安装boost 1.39库及测试代码(转载)

1、 运行【VS目录】/Microsoft Visual Studio 8/VC/bin/vcvars32.bat (或者开始-->所有程序-->Microsoft Visual Studio 2005-->Visual Studio Tools-->Visual Studio 2005命令提示符),然后切换到boost1.39目录。

2、执行 [boost]/tools/jam/build_dist.bat

3、将 [boost]/tools/jam/stage/boost-jam-3.1.17-1-ntx86/bjam.exe 复制到 [boost]/bjam.exe

4、切换到[boost],运行bjam.exe "-sTOOLS=vc-8_0" install

5、在C:/boost下产生include和lib目录,及其近946M的文件。

6、将C:/Boost/include/boost-1_39 加入 VC2005 的 Include 路径

     Tools | Options | Projects and Solutions | VC++ Directories

     Show directories for: Include files

 

    将 C:/Boost/lib 加入 VC2005 的 Lib 路径

    Tools | Options | Projects and Solutions | VC++ Directories

    Show directories for: Library files

7、测试代码

// 正则表达式测试:信用卡号码检测
#include <boost/regex.hpp>
#include <iostream>

bool validate_card_format(const std::string s)
{
        static const boost::regex e("(//d{4}[- ]){3}//d{4}");
        return regex_match(s, e);
}

int _tmain(int argc, _TCHAR* argv[])
{
    std::cout << (validate_card_format("1111-1111-1111-2222")?"PASS":"Error") ; // PASS

    return 0;

}

// 计算两个日期相差的天数
#include <iostream>
#include <boost/date_time/gregorian/gregorian.hpp>

using namespace std;
using namespace boost::gregorian;

int _tmain(int argc, _TCHAR* argv[]){
    date_duration dd = date(2000, 1, 1) - date(1900, 1, 1);
    cout << "The twentieth century had " << dd.days() << " days" << endl; // 36524

    dd = date(2100, 1, 1) - date(2000, 1, 1);
    cout << "The twenty-first century will have " << dd.days() << " days" << endl; // 36525  

    return 0;
}

 

但是某些库还是需要单独编译一下才能使用,比如regex库

因 为最近的一个程序中要用到boost的库,所以在boost的网站上下载了最新的1.34版的源代码。其实以前在VC6的时候是用过的,但这次在 VS2005下安装还是费了不少的工夫的,主要是很多环境变量没有正确的设置的原因。最后终于找到了一个非常方便的方法,共享出来以造福有着同样烦恼的 XDJM们。
1. 启动VS2005,在Tool菜单中选择“Visual Studio 2005 Command Prompt“。VS会启动命令提示符窗口,并自动设置好相应的环境变量。
2. 转到<boost>/libs/regex/build目录下(<boost>是你存放boost代码的路径),运行以下命令即可进行编译,这个过程可能会比较久:
nmake -f vc8.make
3. 运行以下命令进行安装,boost会把上一步产生的lib文件等拷贝到你的VC目录下。
nmake -f vc8.make install
4. 最后清除安装时产生的临时文件:

nmake -f vc8.make clean

------------------

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值