Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5326316
  • 博文数量: 671
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 7310
  • 用 户 组: 普通用户
  • 注册时间: 2006-07-14 09:56
文章分类

全部博文(671)

文章存档

2011年(1)

2010年(2)

2009年(24)

2008年(271)

2007年(319)

2006年(54)

我的朋友

分类: C/C++

2008-09-15 16:04:03

Introduction

The initiative is the next hottest thing after STL for the C++ community. While the documentation is quite good, it can be overwhelming to get a quick start. This simple article explains a method of building Boost libraries. I wrote it because many questions in the newsgroups are about linker errors, which happen if you try to link against some of the Boost libraries. Note that this article was originally written while I worked with the Boost version 1.33. Updated July, 2007: Boost version 1.34 seems to introduce a new syntax for Bjam.

Boost

While most of the Boost libraries are template-based, some of them -- e.g. date-time, regex, filesystem, signals -- come with CPP source files and thus require the actual code to be generated. It uses a build system called Bjam, which can be configured for a lot of platforms. Because I work only on Windows with Visual Studio 2003, I'll describe here a configuration for this combination.

Building Bjam

After downloading the Boost libraries and unpacking them in a folder -- referenced in this article with , e.g. on my PC it is C:\work sdk\boost -- one needs to build the Bjam executable. Browse to \tools\build\jam_src and run build.bat from a command prompt. This will start to build Bjam, which ends up in \tools\build\jam_src\bin.ntx86\bjam.exe. Copy this file to the root of Boost, .

Building Boost

The Bjam system must be told that you want to build debug/release libraries, build with threading in mind, and link against various options of the STL or platforms. Because I only use Visual Studio with Plauger's STL, I have only two options:

  1. Build a debug build with multithreading and dynamic linking for VC++ 7.1.
  2. Build a release build with multithreading and dynamic linking for VC++ 7.1.

This should correspond to the following command line for 1.33:

  1. bjam "-sBUILD=debug dynamic multi" "-sTOOLS=vc-7_1"
  2. bjam "-sBUILD=release dynamic multi" "-sTOOLS=vc-7_1"

For Boost 1.34, different arguments are required:

  1. bjam toolset=msvc-7.1 variant=debug threading=multi link=shared
  2. bjam toolset=msvc-7.1 variant=release threading=multi link=shared

This gives two batch files. Unzip them first, of course:

For Boost 1.34, they should be changed to:

Copy these batch files to the root of Boost, . Now the libraries can be built:

  1. Open the command prompt.
  2. Run vcvars32.bat from Visual Studio.
  3. Run the batch files, e.g. zbuilddebug.bat.

Bjam will now try to build the libraries. After processing, it creates the executables in the \bin directory under their own library names.

  • boost_date_time-vc71-mt-gd-1_33.dll for the multithreaded debug build of a date-time library.
  • boost_date_time-vc71-mt-1_33.dll for the multithreaded release build of a date-time library.

Because all of these files are built under their own library names, one can copy them all -- i.e. search on 'mt-gd-1_33 and mt-1_33 -- to one location and adjust Visual Studio to point to this library location.

Using Boost libraries

We have built the shared libraries and therefore we have to instruct Visual Studio to link against them. Fortunately, Boost has incorporated an "autolink" feature. Thus, with the preprocessor one can link to the correct libraries. Define the following preprocessor statements:

  • BOOST_ALL_DYN_LINK
  • BOOST_LIB_DIAGNOSTIC

Even better, include a header file in your precompiled header before including a Boost header:

Room for improvement

  • For some reason the "normal," i.e. non-dynamic, libraries get built. Can anyone help me with this issue?
  • Python library should also get built, but for some reason it gets excluded.
  • Visual Studio 2005 introduces the safe C and iterator concepts. Boost libraries don't like them and should be turned off. I cannot provide a full solution until I have Visual Studio 2005 myself.

History

  • 11 September, 2005 -- Original version posted
  • 18 July, 2007 -- Updated

License

This article, along with any associated source code and files, is licensed under

阅读(1065) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~