![]() |
General Programming »
Programming Tips »
General
Intermediate
License: The Code Project Open License (CPOL)
Building Boost libraries for Visual StudioBy Gast128Building boost libraries for Visual Studio |
C++ (VC7.1), Windows (WinXP), Visual-Studio, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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.
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.
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:
Bjam can be built in two ways:
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:
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:
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:
Bjam will now try to build the libraries.
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.:
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.
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:
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 18 Jul 2007 Editor: Deeksha Shenoy |
Copyright 2005 by Gast128 Everything else Copyright © CodeProject, 1999-2010 Web17 | Advertise on the Code Project |