Win32 平台 Boost 的编译方法

转自:http://blog.csdn.net/livelylittlefish/archive/2010/12/24/6095619.aspx

Win32 平台 Boost 的编译方法

本文以 boost1.40 为例,在 Win32 平台的编程环境为 vs2005 ,假设 Boost 代码在 E:/opensource/boost_1_40_0 目录,步骤如下。

 

1. 获得 bjam

 

获得 bjam 3 种方式,如下 :

  • 方法 1 Boost 网站上提供了各种平台上预编译好的 bjam 可执行程序,可直接下载使用。
  • 方法 2 :从 Boost 源代码中提供的 bjam 代码编译出可执行程序。
  • 方法 3 :通过 bootstrap 程序生成 bjam

 

此处介绍后两种方法。

 

方法 2

(1) 进入 vs2005 工具的命令行提示符

(2) cd E:/opensource/ boost_1_40_0/tools/jam/src

(3) E:/opensource/boost_1_40_0/tools/jam/src> build.bat
   
或者, E:/opensource/boost_1_40_0/tools/jam/src>build vc8
编译完成后:
      生成的可执行文件为

      E:/opensource/boost_1_40_0/tools/jam/src/ bin.ntx86 / bjam.exe
      需要将 bjam.exe 拷贝到源代码所在的目录
      cp bin.ntx86 / bjam.exe   E:/opensource/ boost_1_40_0

 

方法 3

(1) cd E:/opensource/ boost_1_40_0

(2) E:/opensource/boost_1_40_0 > bootstrap. bat

该方法直接在 Boost 源代码目录下生成 bjam.exe 文件。

 

2. 修改 bjam 配置

 

使用 bjam 前,需要修改 bjam 的配置文件。 Win32 平台的配置文件:

E:/opensource/ boost_1_40_0/tools/build/v2 / user-config.jam

 

修改如下。注:笔者在实验时,不修改貌似也很正常。

57 行的“ # using msvc : 8.0 ; ”前的注释符号‘ # ’去掉,表明用到使用 msvc 8.0 编译。

如果要使用 STLport 作为其标准库,将 75 行前的‘ # ’去掉。

 

3. 完整编译 Boost

 

Boost 进行完整编译,生成所有调试版、发行版的静态库和动态库。

 

方法 1

E:/opensource/boost_1_40_0 > b jam --toolset=msvc --build-type=complete stdlib=stlport stage

E:/opensource/boost_1_40_0 > b jam

 

方法 2

E:/opensource/boost_1_40_0 /t ools / jam > build_dist.bat

也会完成 Win32 平台 bjam Boost 的所有编译工作,并生成所有调试版、发行版的静态库和动态库。 但不推荐该方式。

 

编译成功后,将在 E:/opensource/boost_1_40_0 /bin.v2 目录下生成诸多文件,包括 .dll .lib 文件,这就是 Win32 平台 要使用 Boost 需要的,其他的文件可以删除。

 

4 部分编译 Boost

 

完整编译 Boost 费时费力,且这些库在开发过程中并不一定全部用到,因此, bjam 也支持用户自行选择要编译的库。

 

在完全编译的基础上,使用 --with 或者— without 选择可以打开或者关闭某个库的编译,例如,仅仅编译 date_time 库:

E:/opensource/boost_1_40_0 >b jam --toolset=msvc --with -date_time --build-type=complete stage

 

当然, bjam 还有很多其他选项,如指定安装路径,指定 debug release 等,可参考 bjam 文档 或帮助

 

 

1 bjam 的命令

 

帮助: bjam --help

查看必须编译的库: b jam – - show-libraries

...

 

2 :编译选项说明

  • t oolset 选项

指定器,如 msvc gcc 等。

  • b uild-type 选项

指定编译类型,如果不指定,则默认为 release

  • s tdlib 选项

指定要搭配的标准库,如果不使用 STLport ,可省略该选项。

  • s tage 选项

指定 Boost 使用本地构建。如果使用 install 选项则编译后会把 Boost 安装到默认路径下, Win32 平台为 C:/boost Linux 平台为 /usr/local

 

3 User-config.jam 文件内容


 


 

# Copyright 2003, 2005 Douglas Gregor

# Copyright 2004 John Maddock

# Copyright 2002, 2003, 2004, 2007 Vladimir Prus

# Distributed under the Boost Software License, Version 1.0.

# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt )

 

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

 

#   This file specifies which toolsets (C++ compilers), libraries, and other

# tools are available. Often, you should be able to just uncomment existing

# example lines and adjust them to taste. The complete list of supported tools,

# and configuration instructions can be found at:

#

#   http://boost.org/boost-build2/doc/html/bbv2/reference/tools.html

#

 

#   This file uses Jam language syntax to describe available tools. Mostly,

# there are 'using' lines, that contain the name of the used tools, and

# parameters to pass to those tools -- where paremeters are separated by

# semicolons. Important syntax notes:

#

#   - Both ':' and ';' must be separated from other tokens by whitespace

#   - The '/' symbol is a quote character, so when specifying Windows paths you

#     should use '/' or '//' instead.

#

# More details about the syntax can be found at:

#

#   http://boost.org/boost-build2/doc/html/bbv2/advanced.html#bbv2.advanced.jam_language

#

 

 

# ------------------

# GCC configuration.

# ------------------

 

# Configure gcc (default version).

# using gcc ;

 

# Configure specific gcc version, giving alternative name to use.

# using gcc : 3.2 : g++-3.2 ;

 

 

# -------------------

# MSVC configuration.

# -------------------

 

# Configure msvc (default version, searched for in standard locations and PATH).

# using msvc ;

 

# Configure specific msvc version (searched for in standard locations and PATH).

# using msvc : 8.0 ;

 

 

# ----------------------

# Borland configuration.

# ----------------------

# using borland ;

 

 

# ----------------------

# STLPort configuration.

# ----------------------

 

#   Configure specifying location of STLPort headers. Libraries must be either

# not needed or available to the compiler by default.

# using stlport : : /usr/include/stlport ;

 

# Configure specifying location of both headers and libraries explicitly.

# using stlport : : /usr/include/stlport /usr/lib ;

 

 

# -----------------

# QT configuration.

# -----------------

 

# Configure assuming QTDIR gives the installation prefix.

# using qt ;

 

# Configure with an explicit installation prefix.

# using qt : /usr/opt/qt ;

 


 

Technorati 标签: Boost

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值