windows编译boost库

  • 准备环境:boost_1_70_0.zipVisual Studio 2015
  • 从boost官网下载boost库,下载地址http://www.boost.org/,现在更新到boost_1_70_0,下载boost_1_70_0.zip后解压(我的解压路径是E:\tools\Boost\boost_1_70_0)。历史版本下载地址https://www.boost.org/users/history/
  • 进入主页 

  • 进入下载页 

  • 打开"Microsoft Visual Studio 2015->Visual Studio Tools->Windows Desktop Command Prompts->VS2015 x64 本机工具命令提示符"编译64位平台库。

  • 进入到boost库解压目录E:\tools\Boost\boost_1_70_0。方法是输入“cd /d E:\tools\Boost\boost_1_70_0”回车。

  • 输入“bootstrap.bat”,在E:\tools\Boost\boost_1_70_0目录下生成编译工具bjam.exe,完成bootstrap.bat命令状态如图。

  • 输入“bjam.exe --toolset=msvc-14.0 architecture=x86 link=static --build-type=complete”,编译boost库所有工程的32和64位lib库。

  • 等待编译完成,最后两个路径会在使用boost库时工程属性中包含目录和库目录中用到。 
    • 头文件目录E:\tools\Boost\boost_1_70_0\boost
    • 生成lib库目录E:\tools\Boost\boost_1_70_0\stage\lib

  • 编译生成的lib文件 

  • 注意事项

1.打开"Microsoft Visual Studio 2015->Visual Studio Tools->Windows Desktop Command Prompts->VS2015 x86 本机工具命令提示符"编译32位平台库。
2.只生成一个库的话加上例如--with-system的编译选项,编译两个及以上使用空格分隔,避免生成东西太多、时间太长。
3.如果只编译生成64位库,增加属性address-model=64,如果没有这个属性的话,会默认生成32位和64位的库。
4.--toolset=msvc-14.0是Microsoft Visual Studio的版本,VS2015使用编译器为Microsoft Visual Studio 14.0,其它vs版本如下:

vs2003msvc-7.1
vs2005msvc-8.0
vs2008msvc-9.0
vs2010msvc-10.0
vs2012msvc-11.0
vs2013msvc-12.0
vs2015msvc-14.0
vs2017msvc-15.0
vs2019msvc-16.0

5.link=static要编译静态库版所以属性设置为static,如不要静态库则将static改为shared。

  • link=static和link=shared是指boost生成的动态库还是静态库。
  • runtime-link=static和runtime-link=shared是指boost链接系统运行时库的方式,静态链接或者动态链接。

6.如果要生成Boost.Python库,需要先下载安装x64版的Python安装包,我用的版本是3.2.3。在使用这个库编写Python扩展DLL时,默认是使用动态库版的Boost.Python,要使用静态版的必须在C++项目中定义BOOST_PYTHON_STATIC_LIB宏,这样就不用在使用或发布扩展时带着boost_python-vc90-mt-1_50.dll一起了,当然扩展DLL的尺寸会大些,如果做实验没必要这样,编译又慢生成的文件也大。

  • 以下是Microsoft Visual Studio 2015编译命令汇总
编译所有工程64位lib库bjam.exe --toolset=msvc-14.0 architecture=x86 address-model=64 link=static --build-type=complete
编译指定工程64位lib库bjam.exe --toolset=msvc-14.0 architecture=x86 address-model=64 link=static --build-type=complete --with-system --with-thread --with-date_time --with-filesystem --with-serialization --with-regex --with-python
编译所有工程32和64位lib库bjam.exe --toolset=msvc-14.0 architecture=x86 link=static --build-type=complete
编译指定工程32和64位lib库bjam.exe --toolset=msvc-14.0 architecture=x86 link=static --build-type=complete --with-system --with-thread --with-date_time --with-filesystem --with-serialization --with-regex --with-python
编译所有工程32和64位dll库(动态链接C++标准库,生成debug/Release版)bjam.exe --toolset=msvc-14.0 architecture=x86 link=shared runtime-link=shared --build-type=complete
编译指定工程64位dll库(动态链接C++标准库,生成debug版)bjam.exe --toolset=msvc-14.0 architecture=x86 address-model=64 link=shared runtime-link=shared variant=debug --build-type=complete --with-system --with-thread --with-date_time --with-filesystem --with-serialization --with-regex --with-python
编译指定工程64位dll库(动态链接C++标准库,生成release版)bjam.exe --toolset=msvc-14.0 architecture=x86 address-model=64 link=shared runtime-link=shared variant=release --build-type=complete --with-system --with-thread --with-date_time --with-filesystem --with-serialization --with-regex --with-python
编译指定工程32位dll库(动态链接C++标准库,生成debug版)bjam.exe --toolset=msvc-14.0 architecture=x86 link=shared runtime-link=shared variant=debug --build-type=complete --with-system --with-thread --with-date_time --with-filesystem --with-serialization --with-regex --with-python
编译指定工程32位dll库(动态链接C++标准库,生成release版)bjam.exe --toolset=msvc-14.0 architecture=x86 link=shared runtime-link=shared variant=release --build-type=complete --with-system --with-thread --with-date_time --with-filesystem --with-serialization --with-regex --with-python
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值