Boost库的编译

    技术2026-09-24  5

    一。下载

    boost库2008年3月底发布了1.35.0版本,包括了12个新的库和若干对于新库的修正。请参见http://www.boost.org/users/news/version_1_35_0来获取详细的更新信息。

    最大的喜讯就是提供了对于Visual Studio 2008编译器的支持(1.34也可以,但是需要手工修改)。

    下载地址: http://www.boost.org/users/download/

    boost JAM可以不用下载,源代码已经包括在boost库中,可以直接来编译出来。

    二。准备工作

    编译boost库之前,需要做一些准备工作。下载一些Open Source的包,来 支持boost特定库的需要。

    1. ICU

    ICU提供了unicode和国际化支持,目前的版本是3.8.1。ICU的主页是http://www.icu-project.org/。

    (1). 下载

    可以从http://www.icu-project.org/download/3.8.html下载源代码版本和使用VS2005编译的版本。推荐下载源代码版本自己进行编译,以避免依赖于VS2005的运行时库。

    (2). 编译

    ICU的编译比较简单,打开ICU源代码目录下的source/allinone/allinone.sln,需要转换到VS2008格式,直接转换即可。然后,选择release,Rebuild Solution即可。

    (3). 测试

    将编译出来的bin目录加入到系统的PATH目录中去。然后,重新打开allinone.sln工程。

    需要通过测试的项目

    cintltst项目 intltest项目 iotest

    分别设置成启动项目,运行即可。

    2. bzip

    bzip的主页是 http://www.bzip.org/,从http://www.bzip.org/downloads.html下面下载源代码包即可,boost直接使用源代码来进行编译。

    3. zlib

    zlib的主页是http://www.zlib.net/,从该网页下面下载源代码包即可,boost直接使用源代码来进行编译。

    4. python

    python的主页是http://www.python.org/,下载python的2.5.2版本,安装即可。boost默认是会编译python,并且会自动寻找python的安装目录。

    三。编译

    到开始菜单的VS2008菜单项下,启动Visual Studio 2008 Command Prompt,以下编译步骤均假定直接在该工具下进行编译。

    1. 编译jam

    到tools/jam目录下面运行build_dist.bat,编译好的放在tools/jam/stage/boost-jam-3.1.16-1-ntx86目录下,将bjam.exe复制到boost的根目录。

    2. 编译boost

    鉴于参考2下使用build-type有问题,可以使用以下命令来分别编译dll版本和lib版本。下面是一个示例脚本的例子,其中的目录需要替换:

     

     1 REM used with iostream library   2 REM boost_1_35_0/libs/iostreams/doc/installation.html   3  4 set BZIP2_SOURCE = " E:/library/bzip2-1.0.4 "    5 set ZLIB_SOURCE = " E:/library/zlib123 "    6  7 REM used with regex library with unicode support   8 set ICU_PATH = " E:/library/icu "  9 10 REM DLL版本  11 bjam --toolset = msvc --stagedir = ./lib_x86 --builddir = ./ address-model = 32  link = shared runtime-link = shared threading = multi stage debug release 12 13 REM lib版本  14 bjam --toolset = msvc --stagedir = ./lib_x86 --builddir = ./ address-model = 32  link = static runtime-link = shared threading = multi stage debug release 15

     

     

     

    编译好的文件放置在boost根目录的lib_x86/lib目录下,在boost根目录下的bin.v2目录是中间文件,编译后删除即可。

    如果需要去掉编译过程中的一些warning,可以在tools/build/v2的user-config.jam文件中加入以下这一行:

     

    using msvc : : : <compileflags>/wd4819 <compileflags>/D_CRT_SECURE_NO_DEPRECATE <compileflags>/D_SCL_SECURE_NO_DEPRECATE <compileflags>/D_SECURE_SCL=0 ;

     

     

     

    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 显示需要编译的库名称 8.设置开发环境打开VS2008 创建工程, 配置工程属性设置包含文件目录: /include/boost_1_44_0/boost设置引用文件目录: /boost_1_44_0/stage/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=<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!

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

     

     

    四。参考文章

    1. vs2005下安装boost http://hi.baidu.com/vivid217/blog/item/8e484eafd3b52ff8faed5063.html

    2. boost1.35.0编译日志 http://www.cppblog.com/chemz/archive/2008/03/31/45822.html

    最新回复(0)