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. The build scripts work up to version 1.57.

Boost

While most of the Boost libraries are template-based (i.e. header only), some of them - e.g. date-time, regex, filesystem, signals - come with cpp source files and thus require a library 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, so I'll describe here a configuration for these combination for Visual Studio 2003, 2008, 2010 and 2013.

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:

Build Bjam

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, build static or dynamic library and link against various options of the STL or platforms. I only use Visual Studio with Plauger's STL and choose for the following configuarion

Build a debug build with multithreading and dynamic linking.

Build a release build with multithreading and dynamic linking.

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.

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

boost_date_time-vc120-mt-gd-1_57.dll for the multithreaded debug build of a date-time library.

boost_date_time-vc120-mt-1_57.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_57 and mt-1_57 - 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:

Your project looks for the static library versions (libboost*.lib), instead of the DLL versions. Use the auto linking feature of Boost for correct linking, e.g. use '#define BOOST_ALL_DYN_LINK' before any boost header.

I have an existing application . I downloaded boost library "boost_1_35_0" from this website

http://sourceforge.net/projects/boos.../boost/1.35.0/

and extracted it in program folder

C:\Program Files\boost\boost_1_35_0

and tried your steps, ran those batch files. Since I am using visual studio 2005 so have to make changes in the batch file. I replaced VC9.0 by VC8.0. After running those batch files instead of "libboost_regex-vc80-mt-1_35.lib" it only creates "boost_regex-vc80-mt-gd-1_35.lib". My program always looks for "libboost_regex-vc80-mt-1_35.lib" and throws error

The libboost*.* variants are the static libraries. Either uses dynamic linking (either by Boost's auto linking feature '#define BOOST_ALL_DYN_LINK' or use #include "BoostDefines.hpp" from article before any boost header) or build the static libraries (through runtime-link=static)

Results will be in the stage/lib subdirectory of your boost source directory. Point your VS library include directory to there and you're good to go, for all configurations (static/dynamic linking, debug/release, multi/single threaded runtime, ...)

I built the boost library.
as you said, it created bin directory inside the root directory.
but there are folders are existing as you said. but the dlls and lib files are not existing under these folders. Where I went wrong?

I was using Microsoft Visual Studio 2005 Express to build the boost libraries. I used bjam to do it. The regex library can't be built because of some ICU problem. Some libraries are successful, while others are not. Can anyone help with this?

I recently got interested in Boost again, and a Google search turned up an executable installer that does everything for you. Here's a writeup I did for my co-workers:
If you have Visual Studio 2003 and/or Visual Studio 2005, Boost++ Consulting's installer makes Boost installation much easier than using the 'official' method at boost.org. The installer can also install a convenient Start Menu shortcut for uninstalling the Boost libraries later if you want. To me, the most important advantage of the installer is that the resulting installation of Boost takes significantly less disk space than using the official technique. (The only drawback of using the installer is that it downloads nearly a gigabyte of files, so the whole installation process usually takes a very long time.)

When you run the installer it will ask you a series of questions about which Boost mirror site to download from, which libraries you want to install, and where you want to install them on your hard drive. The installer then downloads appropriate pre-compiled libraries from the selected mirror site and installs them.

The only thing the installer doesn't do is add the necessary directories to your Visual Studio configuration(s). Here's how you do that (the paths below correspond to the default installation path suggested by the installer):

Visual Studio 2003
Tools | Options...
Select the "Projects" folder, then "VC++ Directories".
Select "Include files" in the "Show directories for" drop-down list.
Add the line "C:\Program Files\boost\boost_1_33_1". I usually move it somewhere down near the bottom of the list to make sure the compiler looks for the standard include files and Platform SDK files before looking at the Boost headers.
Select "Library files" in the "Show directories for" drop-down list.
Add the line "C:\Program Files\boost\boost_1_33_1\lib"; again I put it somewhere near the bottom of the list.

Visual Studio 2005
Tools | Options...
Expand the "Projects and Solutions" item in the tree view, and then select "VC++ Directories".
Select "Include files" in the "Show directories for" drop-down list.
Add the line "C:\Program Files\boost\boost_1_33_1". I usually move it somewhere down near the bottom of the list to make sure the compiler looks for the standard include files and Platform SDK files first.
Select "Library files" in the "Show directories for" drop-down list.
Add the line "C:\Program Files\boost\boost_1_33_1\lib"; again I put it somewhere near the bottom of the list.