boost库 - Windows下VS2008中安装boost库

1. 下载文件包:
boost_1_44_0.zip

2. 解压缩至自定义根目录:
D:\boost\boost_1_44_0

3. 安装配置VS2005:
【开始】->【所有程序】->Microsoft Visual Studio 2005】->Visual Studio Tools】->Visual Studio 2005 命令提示】以确保Visual Studio中C++目录下的环境vcvarsall.bat配置脚本得到运行,以配置VS2005的编译器环境变量。

4. 编译获取bjam:
执行D:\boost\boost_1_44_0\tools\jam\src\build.bat,将会生成D:\boost\boost_1_44_0\tools\jam\src\bin.ntx86\bjam.exe,将其复制到D:\boost\boost_1_44_0根目录,确保与boost-build.jam同一目录。

5. 设定编译环境:
修改D:\boost\boost_1_44_0\tools\build\v2\user-config.jam,在
# -------------------
# MSVC configuration.
# -------------------

# Configure msvc (default version, searched for in standard locations and PATH).
# using msvc ;

# Configure specific msvc version (searched for in standard locations and PATH).
# using msvc : 8.0 ;
下方添加:
using msvc : 8.0 : : <compileflags>/wd4819 <compileflags>/D_CRT_SECURE_NO_DEPRECATE <compileflags>/D_SCL_SECURE_NO_DEPRECATE <compileflags>/D_SECURE_SCL=0 ;

注意:如果是VS2008或VS2010则,分别要对应修改成:

using msvc : 9.0 : : <compileflags>/wd4819 <compileflags>/D_CRT_SECURE_NO_DEPRECATE <compileflags>/D_SCL_SECURE_NO_DEPRECATE <compileflags>/D_SECURE_SCL=0 ;

using msvc : 10.0 : : <compileflags>/wd4819 <compileflags>/D_CRT_SECURE_NO_DEPRECATE <compileflags>/D_SCL_SECURE_NO_DEPRECATE <compileflags>/D_SECURE_SCL=0 ;

其中,/wd 是Visual C++ 编译器选项,用于指定编译器如何为给定编译生成警告。
/wd n 表示禁用指定的编译器警告,其中 n 是编译器警告编号。例如,/wd4819 禁用编译器警告 C4819。
在系统中编译 ANSI 源文件时,如果有一个代码页不能表示该文件中的所有字符,则会出现 C4819 警告。
/D(预处理器定义)用于定义源文件的预处理符号。_CRT_SECURE_NO_DEPRECATE、_SCL_SECURE_NO_DEPRECATE、_SECURE_SCL等预处理宏定义分别能屏蔽一部分warning警告信息,详细参见MSDN。
因此,上述添加内容中只是添加了几个编译选项,用于屏蔽一些非必要警告信息。

6. 编译boost:
在D:\boost\boost_1_44_0根目录下执行:
bjam --without-python --toolset=msvc-8.0 --build-type=complete --prefix="D:\boost\boost_1_44_0" install
注意:编译需要时间较长,通常为1小时左右。
如果是VS2008或VS2010,分别对应的命令为:
bjam --without-python --toolset=msvc-9.0 --build-type=complete --prefix="D:\boost\boost_1_44_0" install
bjam --without-python --toolset=msvc-10.0 --build-type=complete --prefix="D:\boost\boost_1_44_0" install

7. 参数说明:
stage/install:stage表示只生成库(dll和lib),install还会生成包含头文件的include目录。
toolset:指定编译器,可选的如borland、gcc、msvc(VC6)、msvc-8.0(VS2005)等。
without/with:选择不编译/编译哪些库。因为python库用不着,所以排除之。
stagedir/prefix:stage时使用stagedir,install时使用prefix,表示编译生成库文件的路径。
build-type:编译类型,complete表示生成所有的版本(debug,release等)。

8. 配置VS2005开发环境:
【工具】->【选项】->【项目和解决方案】->【VC++ 目录】分别添加:
包含文件目录:D:\boost\boost_1_44_0\include\boost-1_44
库文件目录:D:\boost\boost_1_44_0\lib

9. 编写程序测试:
#include <iostream>

#include <boost/lexical_cast.hpp>

int main()
{
    int a = boost::lexical_cast<int>("123");
    double b = boost::lexical_cast<double>("123.0123456789");
    std::string s0 = boost::lexical_cast<std::string>(a);
    std::string s1 = boost::lexical_cast<std::string>(b);
    std::cout << "number is: " << a << " " << b << std::endl;
    std::cout << "string is: " << s0 << " " << s1 << std::endl;

    int c = 0;
    try
    {
        c = boost::lexical_cast<int>("abcd");
    }
    catch (boost::bad_lexical_cast & e)
    {
        std::cout << e.what() << std::endl;
        return -1;
    }

    return 0;
}

10. 执行结果:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值