Click here to Skip to main content
11,483,983 members (70,534 online)
Click here to Skip to main content

Building Boost libraries for Visual Studio

, 18 Jul 2007 CPOL 256.8K 9.2K 102
Rate this:
Please Sign up or sign in to vote.
Building boost libraries for Visual Studio

Introduction

The Boost 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. The original article was written with Boost version 1.33, but the updated version works only with the new Bjam syntax which was introduced with version 1.34.

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 actual code to be generated. Boost uses a build system called Bjam, which can be configured for a lot of platforms. I work only on Windows with Visual Studio 2003, I'll describe here a configuration for this combination. At work though, we already use Visual Studio 2008.

Building Boost

After downloading the Boost libraries and unpacking them in a folder - referenced in this article with <boost_root>, e.g. on my PC it is C:\work sdk\boost, the libraries need to be built:

  1. Build Bjam
  2. Build the Boost libraries

Building Bjam

Bjam can be built in two ways:

  • Use the 'bootstrap.bat' batch file located in <boost_root>. Run this batch file and Bjam will be automatically built and added to the root.
  • Build Bjam 'manually': browse to <boost_root>\tools\build\jam_src and run build.bat from a command prompt. This will start to build Bjam, which ends up in <boost_root>\tools\build\jam_src\bin.ntx86\bjam.exe. Copy this file to the root of Boost, <boost_root>.

Building Boost Libraries

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. I only use Visual Studio with Plauger's STL, but use two different versions of Visual Studio:

  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.
  3. Build a debug build with multithreading and dynamic linking for VC++ 9.0.
  4. Build a release build with multithreading and dynamic linking for VC++ 9.0.

With the release of Visual Studio 2005 / 2008, Microsoft supports side by side installations of the crt. With manifests, one can bind a module to a specific version of the crt. The Boost libraries are dependent on the crt as well, and you can instruct the build process to use the latest version through a '_BIND_TO_CURRENT_VCLIBS_VERSION' define. This leads to the following options for Visual Studio 2003 / 2008:

  1. bjam toolset=msvc-7.1 variant=debug threading=multi link=shared
  2. bjam toolset=msvc-7.1 variant=release threading=multi link=shared
  3. bjam toolset=msvc-9.0 variant=debug threading=multi link=shared define=_BIND_TO_CURRENT_VCLIBS_VERSION
  4. bjam toolset=msvc-9.0 variant=release threading=multi link=shared define=_BIND_TO_CURRENT_VCLIBS_VERSION

I've already made four batch files with the same command(s):

Copy these batch files to the root of Boost, <boost_root>. 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_vc71.bat.

Bjam will now try to build the libraries.

Building All

For the stressful software engineer, I offer here two batch files which will do it all together: they build bjam if it does not exist and build the debug and release mode libraries in one go:

After the build process has finished, the library executables are created in the <boost_root>\bin.v2 directory, e.g.:

  • boost_date_time-vc71-mt-gd-1_41.dll for the multithreaded debug build of a date-time library.
  • boost_date_time-vc71-mt-1_41.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_41 and mt-1_41 - to one location and adjust Visual Studio to point to this library location. Alternatively one can use the <boost_root>\stage directory. However this directory does not contain the associated PDBs, which is unhandy during debugging.

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

History

  • 11 September, 2005 - Original version posted
  • 18 July, 2007 - Updated with Boost 1.34 syntax
  • 25 November 2009 - Updated with manifests and the 'all' batch file; removed old syntax

Credits

  • Leon Wiertz: tip about manifests and the 'all' batch file

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Gast128
Software Developer (Senior)
Netherlands Netherlands
Born in the Netherlands in 1971. Spent since 1998 years as a software engineer programming Windows application(s) using, UML, C++, MFC, STL, DirectShow and Boost.

Comments and Discussions

 
GeneralRe: Some refinements Pin
Chetan Sheladiya3-Nov-09 0:02
memberChetan Sheladiya3-Nov-09 0:02 
QuestionVC2005 Pin
Ed K18-Dec-05 18:31
memberEd K18-Dec-05 18:31 
AnswerRe: VC2005 Pin
Gast12819-Dec-05 9:08
memberGast12819-Dec-05 9:08 
AnswerRe: VC2005 Pin
loadcom5-May-07 1:51
memberloadcom5-May-07 1:51 
GeneralRe: VC2005 Pin
oleg635-Oct-07 11:28
memberoleg635-Oct-07 11:28 
GeneralRe: VC2005 Pin
min_2_max7-Oct-07 15:45
membermin_2_max7-Oct-07 15:45 
GeneralInstall trouble Pin
donburke6-Dec-05 19:47
memberdonburke6-Dec-05 19:47 
GeneralRe: Install trouble Pin
Gast1287-Dec-05 13:12
memberGast1287-Dec-05 13:12 
Hello,

Boost is located on my pc at c:\work sdk\boost (so under this directory, one has the bin, boost, doc, libs etc. subdirectories). Add e.g. 'c:\work sdk\boost' to the include patchs in VS 2003 and one can include regex through:

#include "boost/regex.hpp"

Libs, pdbs and dll's files should be copied (because they are scathered over a lot of subdirectories) to one lib directory and add this to the lib path in VS 2003 (for linking purposes) and environment path variable (for running the application, Windows must find the dll's).


Generalboost or jam build error : &quot;spawn: Invalid argument&quot; Pin
icks9707-Nov-05 22:34
membericks9707-Nov-05 22:34 
GeneralRe: boost or jam build error : &amp;quot;spawn: Invalid argument&amp;quot; Pin
dfhe0606-Dec-05 23:42
memberdfhe0606-Dec-05 23:42 
GeneralRe: boost or jam build error : &amp;quot;spawn: Invalid argument&amp;quot; Pin
Summand3-Jan-06 12:41
memberSummand3-Jan-06 12:41 
GeneralRe: boost or jam build error : &quot;spawn: Invalid argument&quot; Pin
SergeVrt3-Aug-07 4:33
memberSergeVrt3-Aug-07 4:33 
GeneralVisual Studio 6 with STLport 4.6.2 Pin
loadcom19-Sep-05 21:58
memberloadcom19-Sep-05 21:58 
QuestionIJW Support? Pin
Anonymous13-Sep-05 17:29
sussAnonymous13-Sep-05 17:29 
GeneralBjam Error! Pin
xiaohe52112-Sep-05 21:02
memberxiaohe52112-Sep-05 21:02 
GeneralRe: Bjam Error! Pin
loadcom19-Sep-05 22:01
memberloadcom19-Sep-05 22:01 
GeneralThe simplest way Pin
Nemanja Trifunovic12-Sep-05 3:47
memberNemanja Trifunovic12-Sep-05 3:47 
Generalstatic build Pin
gunters12-Sep-05 3:12
membergunters12-Sep-05 3:12 
GeneralRe: static build correction Pin
gunters12-Sep-05 3:14
membergunters12-Sep-05 3:14 
GeneralVisual studio 2002 Pin
Fabien.philippe_codeproject12-Sep-05 1:06
sussFabien.philippe_codeproject12-Sep-05 1:06 
GeneralPractical use of Boost Pin
Patje11-Sep-05 22:28
memberPatje11-Sep-05 22:28 
GeneralRe: Practical use of Boost Pin
Daniel Turini12-Sep-05 5:55
memberDaniel Turini12-Sep-05 5:55 
GeneralRe: Practical use of Boost Pin
Gast12812-Sep-05 7:38
memberGast12812-Sep-05 7:38 
GeneralRe: Practical use of Boost Pin
Eldad13-Sep-05 0:06
memberEldad13-Sep-05 0:06 
GeneralGood job, apply for job as boost documenter Pin
Martin.Holzherr11-Sep-05 21:32
memberMartin.Holzherr11-Sep-05 21:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 18 Jul 2007
Article Copyright 2005 by Gast128
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid