BOOST编译方法
Windows
bjam --toolset=msvc-9.0 --prefix=C:\vc9_boost\vc9  --build-type=complete  link=static  threading=multi install
【一、Boost库的介绍】
Boost库是一个经过千锤百炼、可移植、提供源代码的C++库,作为标准库的后备,是C++标准化进程的发动机之一。 Boost库由C++标准委员会库工作组成员发起,其中有些内容有望成为下一代C++标准库内容。在C++社区中影响甚大,其成员已近2000人。 Boost库为我们带来了最新、最酷、最实用的技术,是不折不扣的“准”标准库。
Boost库中比较有名的几个库:
(1)Regex,正则表达式库;
(2)Spirit,LL parser framework,用C++代码直接表达EBNF;
(3)Graph,图组件和算法;
(4)Lambda,在调用的地方定义短小匿名的函数对象,很实用的functional功能;
(5)concept check,检查泛型编程中的concept;
(6)Mpl,用模板实现的元编程框架;
(7)Thread,可移植的C++多线程库;
(8)Python,把C++类和函数映射到Python之中;
(9)Pool,内存池管理;
(10)smart_ptr,智能指针。
【二、Boost库的编译】
【Setp1 准备工作】:
(1)Boost 下载可以到官方网站下载:
(2)安装VS2008 IDE
【Setp2 编译Boost】
1.打开Visual Studio 2008 命令提示窗口
2.进入D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\boost_1_44_0\tools\jam\src
3.执行 build.bat 会在D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\boost_1_44_0
\tools\jam\src\bin.ntx86 生成 bjam.exe文件.
4.Copy bjam.exe 文件到 D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\boost_1_44_0 下
6.进入D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\boost_1_44_0 目录
7.执行bjam.exe 编译命令,如下:
(1)编译所有boost动态库 (release|debug),包括头文件和库文件
bjam --toolset=msvc-9.0 --prefix=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output --without-python --build-type=complete link=shared threading=multi install
(2)只编译 release 版本 regex 动态库,包括头文件和库文件
bjam --toolset=msvc-9.0 --prefix=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output1 --with-regex link=shared threading=multi variant=release runtime-link=shared install
(3)只编译 release 版本 regex 动态库,包括库文件
bjam --toolset=msvc-9.0
--stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output2
--with-regex link=shared threading=multi variant=release runtime-link=shared stage
【注意】: Boost 源代码所在路径最好全英文,不要有空格、特殊字符、中文等
编译要花上30分钟左右(根据PC性能所定), 会在指定生成目录:
D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output下生成对应库文件和头文件。
8.设置开发环境
打开VS2008 创建工程, 配置工程属性
设置包含文件目录F:\Develop\BoostlibAndDll\include\boost-1_37\boost
设置引用文件目录:F:\Develop\BoostlibAndDll\lib
完成后,可以使用。
【三、介绍Bjam使用】
Usage:
Bjam [options] [properties] [install|stage]
install Install headers and compiled library files to the
======= configured locations (below).
在“--prefix=”指定的目录下生成所有头文件
(boost源代码下boost文件夹下所有文件)和指定库文件
--prefix=<PREFIX> Install architecture independent files here.
Default; C:\Boost on Win32
Default; /usr/local on Unix. Linux, etc.
--exec-prefix=<EPREFIX> Install architecture dependent files here.
Default; <PREFIX>
--libdir=<DIR> Install library files here.
Default; <EPREFIX>/lib
--includedir=<HDRDIR> Install header files here.
Default; <PREFIX>/include
stage Build and install only compiled library files
====== to the stage directory.
在“--stagedir=”指定的目录下生成指定库文件
--stagedir=<STAGEDIR> Install library files here
Default; ./stage
【Other Options】:
--build-type=<type> Build the specified pre-defined set of variations
of the libraries. Note, that which variants get
built depends on what each library supports.
minimal (default) - Builds the single
"release" version of the libraries. This
release corresponds to specifying:
"release <threading>multi <link>shared
<link>static <runtime-link>shared" as the
Build variant to build.
complete - Attempts to build all possible
variations.
--build-dir=DIR Build in this location instead of building
within the distribution tree. Recommended!
--show-libraries Displays the list of Boost libraries that require
build and installation steps, then exit.
--layout=<layout> Determines whether to choose library names
and header locations such that multiple
versions of Boost or multiple compilers can
be used on the same system.
versioned (default) - Names of boost
binaries include the Boost version
number and the name and version of the
compiler. Boost headers are installed
in a subdirectory of <HDRDIR> whose
name contains the Boost version number.
system - Binaries names do not include
the Boost version number or the name
and version number of the compiler.
Boost headers are installed directly
into <HDRDIR>. This option is
intended for system integrators who
are building distribution packages.
--buildid=ID Adds the specified ID to the name of built
libraries. The default is to not add anything.
--help This message.
--with-<library> Build and install the specified <library>
If this option is used, only libraries
specified using this option will be built.
--without-<library> Do not build, stage, or install the specified
<library>. By default, all libraries are built.
【Properties】:
toolset=toolset Indicates the toolset to build with.
msvc-6.0 : VC6.0
msvc-7.0: VS2003
msvc-8.0: VS2005
msvc-9.0: VS2008
msvc-10.0: VS2010
variant=debug|release Select the build variant
link=static|shared Whether to build static or shared libraries
threading=single|multi Whether to build single or multithreaded binaries
runtime-link=static|shared Whether to link to static or shared C and C++ runtime.
决定是静态还是动态链接C/C++标准库
Bjam 选项、参数说明
 
--build-dir=<builddir>
 编译的临时文件会放在builddir里(编译完就可以把它删除了)
 
--stagedir=<stagedir>
 存放编译后库文件的路径,默认是stage
 
--build-type=complete
 编译所有版本,不然只会编译一小部分版本(相当于:
variant=release,threading=multi;
link=shared|static;runtime-link=shared)
 
variant=debug|release
 决定编译什么版本(Debug or Release)
 
link=static|shared
 决定使用静态库还是动态库
 
threading=single|multi
 决定使用单线程还是多线程库
 
runtime-link=static|shared
 决定是静态还是动态链接C/C++标准库
 
--with-<library>
 只编译指定的库,如输入--with-regex就只编译regex库了
 
--show-libraries
 显示需要编译的库名称
【四、Bjam 生成文件的分析】
(1)生成 Release 版本,多线程,动态链接C++标准库 的regex 动态库
bjam --toolset=msvc-9.0
--stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output2
--with-regex link=shared threading=multi variant=release runtime-link=shared stage
-- 输出: boost_regex-vc90-mt.lib
boost_regex-vc90-mt-1_44.lib
boost_regex-vc90-mt-1_44.dll
(2)生成 Release 版本,多线程,静态链接C++标准库 的regex 动态库
bjam --toolset=msvc-9.0
--stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output2
--with-regex link=shared threading=multi variant=release runtime-link= static stage
-- 输出: 没有这种配置
(3)生成 Release 版本,多线程,动态链接C++标准库 的regex静态库
bjam --toolset=msvc-9.0
--stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output2
--with-regex link= static threading=multi variant=release runtime-link=shared stage
-- 输出: libboost_regex-vc90-mt-s.lib
libboost_regex-vc90-mt-1_44.lib
(4)生成 Release 版本,多线程,静态链接C++标准库 的regex 静态库
bjam --toolset=msvc-9.0
--stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output3
--with-regex link=static threading=multi variant=release runtime-link=static stage
-- 输出:libboost_regex-vc90-mt-s.lib
libboost_regex-vc90-mt-s-1_44.lib
--------------------------------------------------------------------------------------------------------------------
(1)生成 Debug 版本,多线程,动态链接C++标准库 的regex 静态库
bjam --toolset=msvc-9.0
--stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output4
--with-regex link=static threading=multi variant=debug runtime-link=shared stage
-- 输出: libboost_regex-vc90-mt-gd.lib
libboost_regex-vc90-mt-gd-1_44.lib
(2)生成 Debug 版本,多线程,静态链接C++标准库 的regex 静态库
bjam --toolset=msvc-9.0
--stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output5
--with-regex link=static threading=multi variant=debug runtime-link=static stage
-- 输出: libboost_regex-vc90-mt-sgd.lib
libboost_regex-vc90-mt-sgd-1_44.lib
(3)生成 Debug 版本,多线程,动态链接C++标准库 的regex 动态库
bjam --toolset=msvc-9.0
--stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output5
--with-regex link=shared threading=multi variant=debug runtime-link=shared stage
- 输出: boost_regex-vc90-mt-gd.lib
boost_regex-vc90-mt-gd-1_44.lib
boost_regex-vc90-mt-gd-1_44.dll
(4)生成 Debug 版本,多线程,静态链接C++标准库 的regex动态库
bjam --toolset=msvc-9.0
--stagedir=D:\05_Computer\04_3rdPatry\02Boost\boost_1_44_0\output5
--with-regex link=shared threading=multi variant=debug runtime-link=static stage
-- 输出:没有这种配置
【总结】:
(1) 编译成功后,Bjam 都会给你生成一对一样的导入库文件或者静态库文件(如下),
唯一不同的是两个文件名称一个在后面加上了boost版本信息, 为了让用户知道使用的boost的版本信息。
boost_regex-vc90-xxxxx.lib
boost_regex-vc90-xxxxx-1_44.lib
(2) Bjam编译选项 有4个, 理论上应该有 2*2*2*2 = 16 种配置
ink= static| shared
threading= single |multi
variant=release|debug
runtime-link= static |shared
实际使用的多为多线程, 所以 threading= multi, 这样剩下的3个选项组成的编译配置就是上面所罗列的, 其中静态链接C++标准库的boost动态库这种配置也不存在, 所以就只有4种情况。
(3)
link= static : 静态库。 生成的库文件名称以 “lib”开头
link= shared : 动态库。生成的库文件名称无“lib”开头
threading= mult : 支持多线程。 生成的库文件名称中包含 “-mt”
variant=release 生成的库文件名称不包含 “-gd”
variant= debug 生成的库文件名称包含 “-gd”
runtime-link= static 生成的库文件名称包含 “-s”
runtime-link= shared 生成的库文件名称不包含 “-s”
一直以来都是在Win32环境下Build和使用boost,但现在基本上每天都在64位Win7下工作,所以很有必要把这几天的经验总结下来。
1. 下载并解压boost 1.61.0 压缩包
2. 解压并运行批处理文件bootstrap.bat,目录下会生成两个可执行文件
3. 和32位环境不同,x64环境下编译得先从开始菜单启动Visual Studio的VS2015 x64 Native Tools Command Prompt 进入命令提示符,而不是随便打开任意一个命令行窗口就行。
4. 然后cd到boost根文件夹,运行bootstrap.bat生成x64版的b2.exe 和 bjam.exe (他们只是版本不同的产物,但是用法一致,bjam是之前版本的,b2 是最新的)
5. 然后运行命令:
b2 --build-type=complete toolset=msvc-14.0 threading=multi link=shared address-model=64
即可生成DLL版平台库,如果要编译静态库版就把shared改为static。
- 只生成一个库的话加上例如--with-python得编译选项,避免生成东西太多、时间太长。
 - 要有address-model=64属性,如果没有这个属性的话,会默认生成32位的平台库,加入这个选项才能生成64位的DLL。
 - 如果要生成Boost.Python库,需要先下载安装x64版的Python安装包,我用的版本是3.2.3。在使用这个库编写Python扩展DLL时,默认是使用动态库版的Boost.Python,要使用静态版的必须在C++项目中定义BOOST_PYTHON_STATIC_LIB宏,这样就不用在使用或发布扩展时带着boost_python-vc90-mt-1_50.dll一起了,当然扩展DLL的尺寸会大些,如果做实验没必要这样,编译又慢生成的文件也大。
 - vs工具链版本:vs2003 : msvc-7.1,vs2005 : msvc-8.0,vs2008 : msvc-9.0,vs2010 : msvc-10.0, vs2015:msvc-14.0
 
生成文件命名规则:boost中有许多库,有的库需要编译、而有的库不需要编译,只需包含头文件就可以使用。编译生成的文件名字普遍较长,同一个库根据编译链接选项不同,又可以生成多个不同名字的文件。生成的文件名字是很长,可是这样带的信息才多,也就容易识别出用途。其实生成文件的名字遵循一定的规则,有着固定的格式。识别这种格式,能帮助我们更高效地使用boost库。生成文件名字格式如:
BOOST_LIB_PREFIX + BOOST_LIB_NAME + "-" + BOOST_LIB_TOOLSET + "-" + BOOST_LIB_THREAD_OPT + "-" + BOOST_LIB_RT_OPT + "-" + BOOST_LIB_VERSION
这些定义为:
BOOST_LIB_PREFIX: 静态库为 "lib" (否则无,是用动态链接库)
BOOST_LIB_NAME: 库的基本名称 ( 比方说 boost_regex).
BOOST_LIB_TOOLSET: 编译工具集名称 ( 比如:vc6, vc7, bcb5 )
BOOST_LIB_THREAD_OPT: 多线程为 "-mt" ,否则为空
BOOST_LIB_RT_OPT: 指示使用的运行库的后缀,
组合下面的一个或者更多字符:
s 静态运行库,指的是静态链接到运行时库(不出现表示动态).
g 调试/诊断 runtime (release if not present).
d 调试版本 (不出现表示 release 版 ).
p STLPort 版本.
注:对 vc 来说,gd 总是一起出现
  BOOST_LIB_VERSION: Boost 版本, Boost 版本 x.y 表示为 x_y形式.
 
 编译:为了简化boost库的编译,boost库中带了一个用来编译的工具,名字是bjam.exe或者b2.exe.
1:运行boost下的bootstap.bat脚本就会自动生上述的两个编译工具,并且拷贝到boost目录下. 也可以进入tools/build目录下找到类似的脚本或者项目源码来编译.
2: bjam.exe的参数
| 
 Feature  | 
 Allowed values  | 
 Notes  | 
| 
 variant  | 
 debug,release  | 
|
| 
 link  | 
 shared,static  | 
 Determines if Boost.Build creates shared or static libraries  | 
| 
 threading  | 
 single,multi  | 
 Cause the produced binaries to be thread-safe. This requires proper support in the source code itself.  | 
| 
 address-model  | 
 32,64  | 
 Explicitly request either 32-bit or 64-bit code generation. This typically requires that your compiler is appropriately configured. Please refer to the section called “C++ Compilers” and your compiler documentation in case of problems.  | 
| 
 toolset  | 
 (Depends on configuration)  | 
 The C++ compiler to use. See the section called “C++ Compilers” for a detailed list. (Vs2008)msvc-8.0 (vs2010)msvc-10.0  | 
| 
 include  | 
 (Arbitrary string)  | 
 Additional include paths for C and C++ compilers.  | 
| 
 define  | 
 (Arbitrary string)  | 
 Additional macro definitions for C and C++ compilers. The string should be either SYMBOL or SYMBOL=VALUE  | 
| 
 cxxflags  | 
 (Arbitrary string)  | 
 Custom options to pass to the C++ compiler.  | 
| 
 cflags  | 
 (Arbitrary string)  | 
 Custom options to pass to the C compiler.  | 
| 
 linkflags  | 
 (Arbitrary string)  | 
 Custom options to pass to the C++ linker.  | 
| 
 runtime-link  | 
 shared,static  | 
 Determines if shared or static version of C and C++ runtimes should be used.  | 
| 
 --build-dir=<builddir>  | 
 编译的临时文件会放在builddir里(这样比较好管理,编译完就可以把它删除了)  | 
| 
 --stagedir=<stagedir>  | 
 存放编译后库文件的路径,默认是stage  | 
| 
 --build-type=complete  | 
 编译所有版本,不然只会编译一小部分版本(确切地说是相当于:variant=release, threading=multi;link=shared|static;runtime-link=shared)  | 
| 
 variant=debug|release  | 
 决定编译什么版本(对应文件中的d 调试版本 不出现表示 release 版)  | 
| 
 link=static|shared  | 
 决定使用静态库还是动态库。(对应文件中的BOOST_LIB_PREFIX )  | 
| 
 threading=single|multi  | 
 决定使用单线程还是多线程库。(对应文件中的BOOST_LIB_THREAD_OPT)  | 
| 
 runtime-link=static|shared  | 
 决定是静态还是动态链接C/C++标准库。(对应文件中的BOOST_LIB_THREAD_OPT)  | 
| 
 --with-<library>  | 
 只编译指定的库,如输入--with-regex就只编译regex库了。  | 
| 
 --show-libraries  | 
 显示需要编译的库名称  | 
bjam.exe --toolset=msvc-10.0 --with-date_time runtimelink=static link=static stage 
意思是要生静态库,该静态库静态链接C运行时库
生成的文件名字是:libboost_date_time-vc100-mt-sgd-1_48.lib(debug version),libboost_date_time-vc100-mt-s-1_48.lib(release version) 两个文件.
bjam.exe --toolset=msvc-10.0 --with-date_time runtimelink=shared link=static stage
意思是要生静态库,该静态库动态链接C运行时库
生成的文件名字是:libboost_date_time-vc100-mt-gd-1_48.lib(debug verion),libboost_date_time-vc100-mt-1_48.lib(release version) 两个文件.
bjam.exe --toolset=msvc-10.0 --with-date_time runtimelink=shared link=shared stage
意思是要生动态库,该动态库动态链接C运行时库
生成的文件名字是:boost_date_time-vc100-mt-gd-1_48.lib(debug version),boost_date_time-vc100-mt-1_48.lib(release version) 两个文件.
生成的dll名字是:boost_date_time-vc100-mt-gd-1_48.dll(debug version),boost_date_time-vc100-mt-1_48.dll(release version)
编译选项方面还有install等参数.
Jsoncpp Linux编译
export SCONS_PATH=/usr/tmp/scons-2.2.0
export SCONS_LIB_DIR=$SCONS_PATH/engine
export JSONCPP_PATH=/usr/tmp/jsoncpp-src-0.6.0-rc2
python $SCONS_PATH/script/scons platform=linux-gcc
BOOST编译方法的更多相关文章
- Linux平台Boost的编译方法
		
本博客(http://blog.csdn.net/livelylittlefish)贴出作 者(三二一@小鱼)相关研究.学习内容所做的笔记,欢迎广大朋友指正! Linux平台Boost的编译方法 Bo ...
 - windows系统,boost编译安装
		
windows系统,boost编译安装vs2017 1.下载https://www.boost.org/users/download/下载windows对应的zip包解压 2.配置vc环境变量我的是: ...
 - boost编译BUG
		
linux GCC环境,boost在编译时未加-fPIC参数,导致如果有共享库使用boost静态库,会报如下错误:relocation R_X86_64_32 against `a local sym ...
 - QxOrm 1.2.9 下载 以及编译方法 简介.
		
QxOrm 是一个基于QT开发的数据库方面的ORM库,功能很强大,是QT C++数据开发方面的好工具. 目前已经更新1.3.1 .但 不幸的是 它的官网http://www.qxorm.com/ 莫名 ...
 - Genome2D编译方法
		
Genome2D是一个高效的2D引擎,现在支持Flash(stage3d)和HTML5,因为只有作者一个人在维护,就没开源代码. 最近和作者沟通了下,已经开源啦. 作者划分了几个模块,编译起来不是特别 ...
 - Spark-1.0.1 的make-distribution.sh编译、SBT编译、Maven编译 三种编译方法
		
fesh个人实践,欢迎经验交流!本文Blog地址:http://www.cnblogs.com/fesh/p/3775343.html 本文编译方法所支持的hadoop环境是Hadoop-2.2.0, ...
 - 详细地jsoncpp编译方法 和 vs2010中导入第三方库的方法
		
详细地jsoncpp编译方法 和 vs2010中导入第三方库的方法 一 编译链接 1 在相应官网下载jsoncpp 2 解压得到jsoncpp-src-0.5.0文件 3 打开jsoncpp-src- ...
 - (DT系列一)DTS结构及其编译方法
		
DTS结构及其编译方法 一:主要问题 1,需要了解dtsi与dts的关系 2,dts的结构模型 3,dts是如何被编译的,以及编译后会生成一个什么文件. 二:参考文字 1,DTS(device tre ...
 - 【转】(DT系列一)DTS结构及其编译方法----不错
		
原文网址:http://www.cnblogs.com/biglucky/p/4057476.html DTS结构及其编译方法 一:主要问题 1,需要了解dtsi与dts的关系 2,dts的结构模型 ...
 
随机推荐
- [LintCode] 用栈实现队列
			
class Queue { public: stack<int> stack1; stack<int> stack2; Queue() { // do intializatio ...
 - react 坑总结
			
1.react可以在里面直接更改state的变量 例如: 2.react 数组循环
 - docker在团队中的实践  How To Install Docker In CentOS
			
" 预发布机器(centos-6.5),给每个同学都开通了ssh这个机器是大家一起共用的,稍后导些数据下来.后续 项目上线,产品测试,都是在这上面进行. 目前在一个物理机 " 3 ...
 - vim_action
			
读取文件,显示行号 nl -a.txt brace expansion 花括号扩展 echo a{A{1,2},B{3,4}}b mkdir {2009...2011}-0{1...9} {2009. ...
 - css中的clear:both,display:flex;
			
介绍两者一起讨论的原因: 在明天就国庆的日子里陪着程序员的只有代码,啤酒,还有音乐,然后就是灯光下默默陪伴自己的影子.好了,不矫情了. -------------------------------- ...
 - Storm-源码分析-acker (backtype.storm.daemon.acker)
			
backtype.storm.daemon.acker 设计的巧妙在于, 不用分别记录和track, stream过程中所有的tuple, 而只需要track root tuple, 而所有中间过程都 ...
 - 常用的SQLalchemy 字段类型
			
https://blog.csdn.net/weixin_41896508/article/details/80772238 常用的SQLAlchemy字段类型 类型名 python中类型 说明 In ...
 - Spring Data 开发环境搭建(二)
			
首先咱们先创建一个maven工程 在pom.xml加入以下 依赖 <!--Mysql 驱动包--> <dependency> <groupId>mysql</ ...
 - 初级学IP地址
			
IP地址是我们上网的凭证!通过IP地址的学习.能够对网络拓扑结构有一个简单的认识,以及对网络的传递过程进行初步了解. 传输数据简单认识 网络中传播的数据是以数据包的形式存在的! 当中包括着目的IP地址 ...
 - sqlite时间段查询
			
同样的SQL语句,查不出数据来 select * from table1 where t1>='2017-6-1' and t1<='2017-6-5' 改成 select * from ...