原文地址:http://hi.baidu.com/hardcorn/blog/item/c8cb1b17284fe7074b90a76f.html
在Win32系统上编译Boost,我们以winxp为例:
boost中包含一个类似于make/nmake的工具:bjam,这是boost所推荐的编译方式,
我们就用bjam来编译boost,而bjam的源码也包含在boost的源码包中。
1. 先编译bjam
a) 将boost源码包解包,我们设BOOST_ROOT代表解包后boost的根目录。
...
D:">cd d:"svn"boost-trunk"
D:"svn"boost-trunk">
b) 到达bjam的源码目录: $(BOOST_ROOT)"tools"jam"src"
...
D:"svn"boost-trunk>cd tools"jam"src
D:"svn"boost-trunk"tools"jam"src>
c) 然后通过执行其中的build.bat来编译bjam, 这个脚本在执行时可以带一个参数,
用来指定编译bjam的编译器, 如果不带任何参数会自动检查当前系统中已安装的编译
器。当前boost在windows平台所支持的编译工具选项有:
borland:
como:
gcc:
gcc-nocygwin:
intel-win32:
metrowerks:
mingw:
msvc: 用VC6.0进行编译
vc7:
vc8:
vc9:
我们让build.bat自己检查,由于我机器上同时安装了vc6.0与vc7.0,build.bat在
自动检查时会从最新的版进行尝试,所以它会用vc7.0编译bjam:
D:"svn"boost-trunk"tools"jam"src>build.bat
"Call_If_Exists"
Setting environment for using Microsoft Visual Studio .NET 2003 tools.
(If you have another version of Visual Studio or Visual C++ installed and wish
to use its tools from the command line, run vcvars32.bat for that version.)
###
### Using 'vc7' toolset.
###
D:"svn"boost-trunk"tools"jam"src>rd /S /Q bootstrap
...
...
...
updated 1 target...
D:"svn"boost-trunk"tools"jam"src>
d) 得到编译好的bjam,编译完成后就会在当前目录下生在一个保存编译结果的目录: bin.平台类型
我的当前的系统是x86上的winxp(nt),所以这个目录为:bin.ntx86,编译好的bjam就保存在这个
目录下:bjam.exe
2. 先用bjam编译boost中的一个库试试,我们就试试编译test库吧。
a) 通过命令行,到达test的库代码目录:
...
D:">cd svn"boost-trunk"libs"test
D:"svn"boost-trunk"libs"test>
b) 在这个目录下有一个文件:Jamfile.v2,bjam.exe通过这个文件来了解如何编译test,它类似与
make/nmake的Makefile文件,我们在这个目录直接调用bjam.exe,就可以编译test:
D:"svn"boost-trunk"libs"test>..".."tools"jam"src"bin.ntx86"bjam.exe
warning: Graph library does not contain optional GraphML reader.
note: to enable GraphML support, set EXPAT_INCLUDE and EXPAT_LIBPATH to the
note: directories containing the Expat headers and libraries, respectively.
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
note: to suppress this message, pass "--without-mpi" to bjam.
note: otherwise, you can safely ignore this message.
...
...
**passed** ..".."bin.v2"libs"test"example"unit_t...
test
...failed updating 2 targets...
...skipped 2 targets...
...updated 434 targets...
c) 默认会编译debug版,且会编译和调用所有单元测试,编译出来的二进制会保存在:
$(BOOST_ROOT)"bin.v2:
D:"svn"boost-trunk>cd bin.v2
D:"svn"boost-trunk"bin.v2>tree
文件夹 PATH 列表
卷序列号码为 000007BC 6057:AC36
D:.
└─libs
├─test
│ ├─build
│ │ └─msvc-7.1
│ │ └─debug
│ │ └─asynch-exceptions-on
│ │ ├─link-static
│ │ │ └─threading-multi
│ │ └─threading-multi
│ ├─example
│ │ ├─const_string_test.test
│ │ │ └─msvc-7.1
│ │ │ └─debug
│ │ │ └─threading-multi
│ │ ├─est_example1.test
│ │ │ └─msvc-7.1
│ │ │ └─debug
│ │ │ └─threading-multi
│ │ ├─est_example2.test
│ │ │ └─msvc-7.1
│ │ │ └─debug
│ │ │ └─threading-multi
│ │ ├─exec_mon_example.test
│ │ │ └─msvc-7.1
...........
3. 编译整个boost:
a) 在boost的根目录下有一个文件:Jamroot,我们在boost根目录下直接执行bjam.exe,就可以
能过这个文件编译根个boost库。
D:"svn"boost-trunk>tools"jam"src"bin.ntx86"bjam.exe
warning: Graph library does not contain optional GraphML reader.
note: to enable GraphML support, set EXPAT_INCLUDE and EXPAT_LIBPATH to the
note: directories containing the Expat headers and libraries, respectively.
warning: skipping optional Message Passing Interface (MPI) library.
note: to enable MPI support, add "using mpi ;" to user-config.jam.
.......
b) Jamroot文件中有很多可用的编译选项,可以用文件编辑器打开这个文件,来了解更从的编译细节。
例如,可以通过参数来有选择的编译(或不编译)boost的中指定库,如测试库:
D:"svn"boost-trunk>tools"jam"src"bin.ntx86"bjam.exe --with-test stage