5,666,979 members and growing! (15,284 online)
Email Password   helpLost your password?
General Programming » Programming Tips » General     Intermediate License: The Code Project Open License (CPOL)

Building Boost libraries for Visual Studio

By Gast128

Building boost libraries for Visual Studio.
VC7.1, C++Windows, WinXP, Visual Studio, Dev

Posted: 11 Sep 2005
Updated: 18 Jul 2007
Views: 81,100
Bookmarked: 56 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
29 votes for this Article.
Popularity: 6.55 Rating: 4.48 out of 5
2 votes, 6.9%
1
2 votes, 6.9%
2
0 votes, 0.0%
3
4 votes, 13.8%
4
21 votes, 72.4%
5

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. 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 <boost_root>, e.g. on my PC it is C:\work sdk\boost -- one needs to build the Bjam executable. 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

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 <runtime-link>dynamic <threading>multi" "-sTOOLS=vc-7_1"
  2. bjam "-sBUILD=release <runtime-link>dynamic <threading>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, <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.bat.

Bjam will now try to build the libraries. After processing, it creates the executables in the <boost_root>\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 The Code Project Open License (CPOL)

About the Author

Gast128


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

Other popular Programming Tips articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 45 (Total in Forum: 45) (Refresh)FirstPrevNext
GeneralEasy way to build boost for VS 2008memberroel_4:45 1 Sep '08  
Generalcan this article be updatedmembermeirab13:48 18 Dec '07  
General( solution for vc++ 2005(studio) boost/regex 1.3.41 )membermeirab7:32 20 Dec '07  
GeneralRe: can this article be updatedmemberGast12811:38 28 Aug '08  
GeneralHow to compile 64-bit serialization library with VS2005?memberoleg636:50 9 Oct '07  
GeneralBoost: Where the DLLs are getting created?memberSarath.4:26 3 Feb '07  
GeneralRe: Boost: Where the DLLs are getting created?memberGast1284:02 4 Feb '07  
GeneralRe: Boost: Where the DLLs are getting created?memberSarath.5:26 4 Feb '07  
QuestionCompiling boost with stdcxx STLmembernadinefaizant7:22 6 Nov '06  
QuestionMissing Boost regex libs when buiding using VC8 expressmemberyhuo3:24 19 Sep '06  
GeneralAn even easier way to install BoostmemberGordon Brandly20:02 22 Aug '06  
GeneralRe: An even easier way to install Boostmembermmuekk22:55 6 Aug '07  
Generalbuilding boost librariesmemberlconklin18:27 25 Jul '06  
Generalhelp me out for spawning error.membernitinjdalal1:12 12 Jun '06  
GeneralLife savermemberogrig19:29 20 Apr '06  
GeneralVS 2003memberAnthony_Yio16:32 14 Feb '06  
GeneralRe: VS 2003memberFlying_oe15:22 2 Mar '06  
GeneralSome refinementsmemberNetCE12:21 13 Feb '06  
GeneralRe: Some refinementsmemberoleg6311:51 5 Oct '07  
QuestionVC2005memberEd K18:31 18 Dec '05  
AnswerRe: VC2005memberGast1289:08 19 Dec '05  
AnswerRe: VC2005memberloadcom1:51 5 May '07  
GeneralRe: VC2005memberoleg6311:28 5 Oct '07  
GeneralRe: VC2005membermin_2_max15:45 7 Oct '07  
GeneralInstall troublememberdonburke19:47 6 Dec '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 18 Jul 2007
Editor: Genevieve Sovereign
Copyright 2005 by Gast128
Everything else Copyright © CodeProject, 1999-2008
Web09 | Advertise on the Code Project