Boost库的编译

【二、Boost库的编译】
【Setp1 准备工作】:
1 Boost 下载可以到官方网站下载:https://www.360docs.net/doc/b115914059.html,/
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:\ThirdParty\boost_1_44_0\boost-1_44\stage --without-python --build-type=complete link=shared threading=multi install

(2)只编译 release 版本 regex 动态库,包括头文件和库文件
bjam --toolset=msvc-9.0 --prefix=D:\ThirdParty\boost_1_44_0\boost-1_44\stage --with-regex link=shared threading=multi variant=release runtime-link=shared install

(3)只编译 release 版本 regex 动态库,包括库文件
bjam --toolset=msvc-9.0 --stagedir=D:\ThirdParty\boost_1_44_0\boost-1_44\stage --with-regex link=shared threading=multi variant=release runtime-link=shared stage

【注意】: Boost 源代码所在路径最好全英文,不要有空格、特殊字符、中文等
编译要花上30分钟左右(根据PC性能所定), 会在指定生成目录:
D:\ThirdParty\boost_1_44_0\boost-1_44\stage下生成对应库文件和头文件。

Bjam 选项、参数说明
--build-dir= 编译的临时文件会放在builddir里(编译完就可以把它删除了)
--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- 只编译指定的库,如输入--with-regex就只编译regex库了
--show-libraries 显示需要编译的库名称

8.设置开发环境
打开VS2008 创建工程, 配置工程属性
设置包含文件目录: \include\boost_1_44_0\boost
设置引用文件目录: \boost_1_44_0\stage\lib
完成后,可以使用。

【四、Bjam 生成文件的分析】
(1)生成 Release 版本,多线程,动态链接C++标准库 的regex 动态库
bjam --toolset=msvc-9.0 --stagedir=D:\ThirdParty\boost_1_44_0\boost-1_44\stage --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:\ThirdParty\boost_1_44_0\boost-1_44\stage --with-regex link=shared threading=multi variant=release runtime-link= static stage

-- 输出: 没有这种配置

(3)生成 Release 版本,多线程,动态链接C++标准库 的regex静态库
bjam --toolset=msvc-9.0 --stagedir=D:\ThirdParty\boost_1_44_0\boost-1_44\stage --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:\ThirdParty\boost_1_44_0\boost-1_44\stage --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:\ThirdParty\boost_1_44_0\boost-1_44\stage --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:\ThirdParty\boost_1_44_0\boost-1_44\stage --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:\ThirdParty\boost_1_44_0\boost-1_44\stage --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:\ThirdParty\boost_1_44_0\boost-1_44\stage --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”

【Other Options】:

--build-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 multi shared

static 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!

bjam --show-libraries Displays the list of Boost libraries that require build and installation steps, then exit.

--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 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 . 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- Build and install the specified

If this option is used, only libraries


specified using this option will be built.



--without- Do not build, stage, or install the specified

. 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.



本文来自CSDN博客,转载请标明出处:https://www.360docs.net/doc/b115914059.html,/xucuiping_/archive/2010/10/27/5970455.aspx

相关文档
最新文档