The Boost C++ Libraries


The Boost libraries come as source code. While most of the libraries consist solely of header files that can be used directly, some of the libraries require compilation. In order to make installation as easy as possible, an automated installation process based on Boost.Build is available. Instead of validating and compiling individual libraries separately, Boost.Build installs the complete set automatically. Boost.Build can be used with many operating systems and compilers and is able to compile each individual library based on appropriate configuration files.

To automatically install the Boost libraries with Boost.Build, the command-line program bjam is used. The Boost libraries ship this program as source code and not as an executable. Therefore, two steps are required to build and install the Boost libraries. After you download the Boost libraries, change to the Boost directory and enter the following commands on the command line:

  1. Enter bootstrap on Windows and ./ on other platforms, such as Linux, to compile bjam. The script automatically searches for a C compiler to build bjam.

  2. Then, enter bjam on Windows and ./bjam on other platforms to start installing the Boost libraries.

You use bootstrap only once to build bjam. However, you might need to use bjam more often because bjam supports command-line options to build the Boost libraries in different ways. If you start bjam without any command-line options, a default configuration will be used. Because the default configuration is not always appropriate, you should know the most important command-line options:

To create both debug and release builds of the Boost libraries with Visual C++ 2013 and install them in the directory D:\Boost, enter the following command:

bjam --toolset=msvc-12.0 --build-type=complete --prefix=D:\Boost install

To build them on Linux and install them in the default directory, the command would be:

bjam --toolset=gcc --build-type=complete install

There are many other command-line options that you can use to specify in detail how to compile the Boost libraries. Have a look at the following command:

bjam --toolset=msvc-12.0 debug release link=static runtime-link=shared install

The debug and release options cause both debug and release builds to be generated. link=static only creates static libraries. runtime-link=shared specifies that the C++ runtime library is dynamically linked, which is the default setting for projects in Visual C++ 2013.