Win32平台Boost的编译方法

来源:互联网 发布:拍卖系统安卓as源码 编辑:程序博客网 时间:2024/05/16 14:09

本博客(http://blog.csdn.net/livelylittlefish )贴出作 者(三二一@小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!

 

Win32平台Boost的编译方法

 

 

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

 

1. 获得bjam

 

获得bjam3种方式,如下:

  • 方法1Boost网站上提供了各种平台上预编译好的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>bjam --toolset=msvc --build-type=complete stdlib=stlport stage

E:/opensource/boost_1_40_0>bjam

 

方法2

E:/opensource/boost_1_40_0/tools/jam>build_dist.bat

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

 

编译成功后,将在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>bjam --toolset=msvc --with-date_time --build-type=complete stage

 

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

 

 

1bjam的命令

 

帮助:bjam --help

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

...

 

2:编译选项说明

  • toolset选项

指定器,如msvcgcc等。

  • build-type选项

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

  • stdlib选项

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

  • stage选项

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

 

3User-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