Boost库的编译

一。下载

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工程。

需要通过测试的项目

  1. cintltst项目
  2. intltest项目
  3. 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
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Boost是一个开源的C++集合,提供了许多功能强大的组件和工具,用于增强C++语言的功能和性能。Qt是一个跨平台的应用程序开发框架,而MinGW是一个在Windows平台上使用的GNU工具集。 要编译Boost并与Qt和MinGW一起使用,可以按照以下步骤进行操作: 1. 下载Boost:首先,你需要从Boost官方网站(https://www.boost.org/)下载Boost的源代码。选择适合你的操作系统和编译器的版本。 2. 解压Boost:将下载的Boost源代码解压到你选择的目录中。 3. 打开命令提示符:在Windows上,按下Win + R键,输入"cmd"并按下Enter键,打开命令提示符。 4. 进入Boost目录:使用cd命令进入你解压Boost源代码的目录。 5. 运行bootstrap.bat:在命令提示符中运行bootstrap.bat脚本文件,它将为你的系统配置编译环境。 6. 编译Boost:运行b2命令来编译Boost。你可以使用一些选项来指定编译器和其他参数。例如,如果你想使用MinGW编译器,可以运行以下命令: ``` b2 toolset=gcc ``` 7. 安装Boost编译完成后,运行b2 install命令来安装Boost。这将把编译好的文件复制到指定的目录中。 8. 配置Qt项目:在Qt项目中使用Boost时,你需要在项目文件(.pro文件)中添加相应的配置。例如,如果你想使用Boost的某个模块,可以在.pro文件中添加以下行: ``` LIBS += -lboost_module INCLUDEPATH += /path/to/boost ``` 以上是编译Boost并与Qt和MinGW一起使用的基本步骤。具体的配置和使用方法可能因你的项目需求和环境而有所不同。如果遇到问题,可以参考Boost官方文档或在相关社区寻求帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值