说明

C++11出现前的很多“新”C++特性是在Boost库里面出现的,深度学习框架Caffe用到了Boost。编译Boost是为了解决历史遗留问题,新开发库应当直接用C++11或更高的C++标准来获得新的语言特性、库函数。

Boost使用自己的构建工具。早期叫bjam,新版叫b2。执行bootstrap命令后生成b2.exe和bjam.exe,执行哪个都一样。执行编译时是在“黑框框”(cmd命令行)中运行的,而不是在Visual Studio这样的IDE里编译,因此一旦有编译错误找起来略微麻烦。

Boost是一系列模块的组合,需要哪个子模块就编译它。例如需要filesystem模块,编译时指定--with-filesystem

基本设定

  • boost源码版本:boost1.61.0
  • 解压到F:\zhangzhuo\lib\boost-1.61.0目录
  • python:我的系统同时存在python2和python3(miniconda设定的),--with-python会很友好的编译出py2和py3的包
  • (可选)project-config.jam文件,用来配置项目中的一些设定,例如VS编译器、Python版本等
  • (可选)b2构建工具的文档:https://boostorg.github.io/build/manual/master/index.html
  • (可选)指定toolset的版本,实际上是VC的编译器toolset的版本:(来自b2文档)
Visual Studio 2019-14.2

Visual Studio 2017—14.1

Visual Studio 2015—14.0

Visual Studio 2013—12.0

Visual Studio 2012—11.0

Visual Studio 2010—10.0

Visual Studio 2008—9.0

Visual Studio 2005—8.0

Visual Studio .NET 2003—7.1

Visual Studio .NET—7.0

Visual Studio 6.0, Service Pack 5—​6.5

编译

1. bootstrap

进入目录:

f:
cd F:\zhangzhuo\lib\boost-1.61.0

执行bootstrap脚本:

bootstrap.bat

输出:

F:\zhangzhuo\lib\boost-1.61.0>bootstrap.bat
Building Boost.Build engine Bootstrapping is done. To build, run: .\b2 To adjust configuration, edit 'project-config.jam'.
Further information: - Command line help:
.\b2 --help - Getting started guide:
http://boost.org/more/getting_started/windows.html - Boost.Build documentation:
http://www.boost.org/build/doc/html/index.html

2. 修改源码(编译报错处理)

问题1:libs\python\src\converter\builtin_converters.cpp(51): error C2440: 'return': cannot convert from 'const char *' to 'void *'

我用的是boost1.61.0,解决办法:修改libs/python/src/converter/convert_to_cstring.cpp,找到convert_to_cstring()函数,修改前若干行为:

#if PY_VERSION_HEX < 0x03000000
void* convert_to_cstring(PyObject* obj)
{
return PyString_Check(obj) ? PyString_AsString(obj) : 0;
}
#elif PY_VERSION_HEX < 0x03070000
void* convert_to_cstring(PyObject* obj)
{
return PyUnicode_Check(obj) ? _PyUnicode_AsString(obj) : 0;
}
#else
void* convert_to_cstring(PyObject* obj)
{
return PyUnicode_Check(obj) ? const_cast<void*>(reinterpret_cast<const void*>(_PyUnicode_AsString(obj))) : 0;
}
#endif

参考:

https://stackoverflow.com/questions/54991157/cant-compile-boost-python-1-65-1-with-msvc2015

https://github.com/boostorg/python/commit/660487c43fde76f3e64f1cb2e644500da92fe582#diff-467cabb22a6c637452d730accca26d2e

3. 编译脚本

boost根目录新建vs2013-x64.bat,内容:

b2.exe toolset=msvc-12.0 --build-type=complete address-model=64 ^
--with-serialization ^
--with-system ^
--with-date_time ^
--with-regex ^
--with-filesystem ^
--with-timer ^
--with-chrono ^
--with-program_options ^
--with-thread ^
--with-python ^
--stagedir="test"

其中--stagedir指定的目录为test,它下面有个lib目录,把编译好的dll和lib都放在这里了。

执行构建:把输出重定向到日志方便查错:

vs2013-x64.bat > log.txt 2>&2


旧版内容:

要用xx库,编译boost时就指定--with-xx。例如:

# 下载并解压boost_1.58
# 进入boost_1.58目录 bjam.exe toolset=msvc-14.0 --build-type=complete address-model=64 --with-serialization --with-system --with-date_time --with-regex --with-filesystem --with-timer --with-chrono --with-program_options --with-thread --with-python --stagedir="test"

说明:

  • msvc-14.0表示visual studio 2015

  • --stagedir指定的目录为test,它下面有个lib目录,把编译好的dll和lib都放在这里了。

windows上编译boost库的更多相关文章

  1. IOS上编译boost库

    环境:xcode9mac os 10.13 1.下载boost库并解压2.cd到解压后的文件包内,执行 sh bootstrap.sh(解压后会得到这个脚本文件).3.执行./b2 编译整个库.4.经 ...

  2. windows下编译Boost库

    下载源码 boost_1_66_0.7z 生成编译工具 D:\Project\boost_1_66_0> bootstrap.bat 配置Python环境变量(使用VS2017自带的32位pyt ...

  3. 在windows上编译apr库

    环境: win7_x64旗舰版.VS2015企业版.CMake3.8 一.下载apr相关库 1.1)expat下载地址:https://github.com/libexpat/libexpat/rel ...

  4. Windows上编译Boost

    Boost做得很好,有自己的build系统,可以几乎一键式编译,这才是尼玛世界一流质量的良心开源库啊. 将Boost 1.49.0解压到boost/boost_1_49_0里面,然后在boost目录底 ...

  5. [ZZ] 在windows上编译Mesa3d opengl32库

    在windows上编译Mesa3d opengl32库 cheungmine http://blog.csdn.net/ubuntu64fan/article/details/8061475 Mesa ...

  6. 如何在WINDOWS下编译BOOST C++库 .

    如何在WINDOWS下编译BOOST C++库 cheungmine 2008-6-25   写出来,怕自己以后忘记了,也为初学者参考.使用VC8.0和boost1.35.0.   1)下载boost ...

  7. 利用openssl管理证书及SSL编程第2部分:在Windows上编译 openssl

    利用openssl管理证书及SSL编程第2部分:在Windows上编译 openssl 首先mingw的环境搭建,务必遵循下文: http://blog.csdn.net/ubuntu64fan/ar ...

  8. 在windows上编译wireshark源代码

    终于在windows上成功编译了wireshark源代码,个中酸辛,都是泪..只能说要多试! windows上编译wireshark共用到三个东西:wireshark源代码.python.cygwin ...

  9. 在Mac/Linux/Windows上编译corefx遇到的问题及解决方法

    这两天尝试在Mac/Linux/Windows三大平台上编译.NET跨平台三驾马车(coreclr/corefx/dnx)之一的corefx(.NET Core Framework),结果三个平台的编 ...

随机推荐

  1. 在Vue中的load或ready的加载时机

    在Vue中的load或ready的加载时机 1.我们来插入一段代码来分析: Js代码如下 <script type="text/javascript"> var app ...

  2. 【运维】浪潮服务器一块硬盘显示红色Offline(或者Failed)解决办法

    [写在前面]           最近服务器不知道为什么总是出现故障,以前戴尔服务器硬盘出现故障,也就是说硬盘旁边的灯显示为红色的时候,一般情况下都是表示硬盘坏掉了,直接买一块新的硬盘,将坏掉的硬盘拿 ...

  3. Latex自定义文档纸张大小

    \usepackage{geometry} \special{papersize=8.5in,11in}%纸张大小为8.5inch×11inch

  4. 【转】python f-string

    [转]python f-string   文章目录 1. 主要内容 1.1. 旧时代的格式化字符串 1.1.1. Option #1: %-formatting 1.1.2. 怎样使用 %-forma ...

  5. Linux网络底层收发探究【转】

    转自:https://blog.csdn.net/davion_zhang/article/details/51536807 本文为博主原创文章,未经博主允许不得转载. https://blog.cs ...

  6. 网页块元素定位建议使用的xpath方式

    取上图的新手上路文字 使用xpath "//div[@class='pbm mbm bbda cl']//li[contains(string(),'用户组')]/span/a/text() ...

  7. Python3学习笔记31-xlrd模块

    xlrd模块是用来读取excel的第三方模块,需要下载安装后才能使用.新建一个excel,随便填充一些数据用来测试下. ​ # -*- coding: utf-8 -*- import xlrd #打 ...

  8. 【转】Linux中profile、bashrc、bash_profile之间的区别和联系

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登陆时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置. 英文描述为: # /etc/pr ...

  9. CANopen--Copley驱动器 ACJ-055-18 过程数据PDO的断电保存方法

    Copley CANopen 系列驱动器中,均保存有默认的 PDO 设置, 如下图所示 实际使用中,往往需要修改默认的 PDO 配置,以映射不同模式或功能下的 PDO 对象,但由于 PDO 配置无法存 ...

  10. GridView的stretchMode属性

    stretchMode属性值的作用是设置GridView中的条目以什么缩放模式去填充剩余空间.参数stretchMode 可选值为:none,spacingWidth,columnWidth, spa ...