0.Boost库编译基本理解
VS命令提示符窗口中先编译bjam编译工具,然后对需要的boost库进行编译。
VS命令提示符窗口中先编译bjam编译工具,然后对需要的boost库进行编译。
对需要的boost库进行编译:
编译调试版本加 debug
编译发布版本加 release
编译静态链接库:
link=
static
runtime-link=
static
编译动态库:link=shared runtime-link=shared
静态库只是需要的文件编译到exe/so中,而且shared的是否用户也要存在dll,所以static是更安全的方式;当然组件式开发和升级的软件用shared方式更加合适(他们都是隐式调用的,dll的显示调用太麻烦了)。
静态库只是需要的文件编译到exe/so中,而且shared的是否用户也要存在dll,所以static是更安全的方式;当然组件式开发和升级的软件用shared方式更加合适(他们都是隐式调用的,dll的显示调用太麻烦了)。
示例:
--toolset=msvc-9.0 architecture=x86 link=static runtime-link=static threading=multi debug release --with-property_tree --with-program_options
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
linux下面:
./bjam --build-type=minimal --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread variant=release link=static threading=multi stage
boost中的thread需要编译成dll才能使用。
首先,获取boost代码,可以在cmd中敲入
cvs -d:pserver:anonymous@boost.cvs.sourceforge.net:/cvsroot/boost login
cvs -z3 -d:pserver:anonymous@boost.cvs.sourceforge.net:/cvsroot/boost co -P boost
来获取boost的cvs中的代码
然后在cmd(VS命令提示符窗口中编译)中进入boost/tools/jam/src,执行build.bat
这样,就编译好了jam这个工具,在x86windows平台下,可以在boost/tools/jam/src/bin.ntx86这个目录找到编译好的bjam.exe
把当前目录退回到boost的根目录,执行tools/jam/src/bin.ntx86/bjam.exe --with-thread stage,这样,就能在boost/stage/lib中找到编译好的thread库。
tools/jam/src/bin.ntx86/bjam.exe --with-date_time stage 可以编译date_time模块,好像模块刚好是boost的文件夹。
如果要gd类型的也就是debug类型的库,那么
tools/jam/src/bin.ntx86/bjam.exe --with-thread stage debug release
即可
1.Bjam 选项、参数说明
--toolset=msvc 指定编译器,如果使用其他的编译器,可以自行指定,borland(对应BCB)或msvc(对应VC)或gcc(对应Mingw)
--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) ,默认是Release
link=static|shared 决定使用静态库还是动态库,默认是
shared
threading=single|multi 决定使用单线程还是多线程库 ,多个线程都可以访问相同变量否,默认应是single non-thread safe待验证
runtime-link=static|shared动态库的静态调用还是动态调用C/C++标准库 ,默认应该是shared 待验证,动态库的动态调用,静态库没有这个区别
--with-<library> 只编译指定的库,如输入--with-regex就只编译regex库了
--without-<library> Do not build, stage, or install the specified
--show-libraries 显示需要编译的库名称 可以用--with来编译
静态库和动态的引入和其它库一样,引入头文件,包含库即可。
2.更多使用示例:
using msvc : 9.0 : : /wd4819 /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 ;
bjam --toolset=msvc-9.0 --prefix=D:\boost_1_47_0\BoostLibAndDll --build-type=complete install
(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
--------------------------------------------------------------------------------------------------------------------
(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
-- 输出:没有这种配置
linux下编译
# cd /usr/src/boost_1_40_0
# ./bjam --toolset=msvc --with-date_time --build-type=complete stage
bjam --with-python --toolset=msvc-10.0 --build-type=complete --prefix="d:\boost\boost_1_48_0" install
3.bjam 命令说明
Boost.Build V2 (Milestone 12)
Boost.Jam 03.1.16
Project-specific help:
Project has jamfile at Jamroot
Usage:
bjam [options] [properties] [install|stage]
Builds and installs Boost.
Targets and Related Options:
install Install headers and compiled library files to the
======= configured locations (below).
--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> 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
Boost.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.
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.
Configuration help:
Configuration file at $boost$\tools\build\v2
user-config.jam
This file is used to configure your Boost.Build installation. You can modify
this file in place, or you can place it in a permanent location so that it
does not get overwritten should you get a new version of Boost.Build. See:
http://boost.org/boost-build2/doc/html/bbv2/reference.html#bbv2.reference.init
for documentation about possible permanent locations.
General command line usage:
bjam [options] [properties] [targets]
Options, properties and targets can be specified in any order.
Important Options:
* --clean Remove targets instead of building
* -a Rebuild everything
* -n Don't execute the commands, only print them
* -d+2 Show commands as they are executed
* -d0 Supress all informational messages
* -q Stop at first error
* --debug-configuration Diagnose configuration
* --debug-building Report which targets are built with what properties
* --debug-generator Diagnose generator search/execution
Further Help:
The following options can be used to obtain additional documentation.
* --help-options Print more obscure command line options.
* --help-internal Boost.Build implementation details.
* --help-doc-options Implementation details doc formatting.
Boost.Build V2 (Milestone 12)
Boost.Jam 03.1.16
Project-specific help:
Project has jamfile at Jamroot
Usage:
bjam [options] [properties] [install|stage]
Builds and installs Boost.
Targets and Related Options:
install Install headers and compiled library files to the
======= configured locations (below).
--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> 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
Boost.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.
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.
Configuration help:
Configuration file at $boost$\tools\build\v2
user-config.jam
This file is used to configure your Boost.Build installation. You can modify
this file in place, or you can place it in a permanent location so that it
does not get overwritten should you get a new version of Boost.Build. See:
http://boost.org/boost-build2/doc/html/bbv2/reference.html#bbv2.reference.init
for documentation about possible permanent locations.
General command line usage:
bjam [options] [properties] [targets]
Options, properties and targets can be specified in any order.
Important Options:
* --clean Remove targets instead of building
* -a Rebuild everything
* -n Don't execute the commands, only print them
* -d+2 Show commands as they are executed
* -d0 Supress all informational messages
* -q Stop at first error
* --debug-configuration Diagnose configuration
* --debug-building Report which targets are built with what properties
* --debug-generator Diagnose generator search/execution
Further Help:
The following options can be used to obtain additional documentation.
* --help-options Print more obscure command line options.
* --help-internal Boost.Build implementation details.
* --help-doc-options Implementation details doc formatting.
参考文章:
http://www.boost.org/build/doc/html/bbv2/overview/invocation.html