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:
bootstrap on Windows and
./bootstrap.sh on other platforms, such as Linux, to compile bjam. The script automatically searches for a C compiler to build bjam.
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:
The command-line options
install specify whether the Boost libraries are installed in a subdirectory called
stage or are made available system wide. The meaning of system wide depends on the operating system. On Windows, the target directory is
C:\Boost; on Linux it is
/usr/local. The target directory can also be specified with the
--prefix option. Starting bjam without command-line options always means
If bjam is called without any command-line options, it will search for a suitable C++ compiler. A specific compiler can be selected using the
--toolset option. To select Visual C++ 2013 on Windows, call bjam with
--toolset=msvc-12.0. To select the GCC compiler on Linux, use
The command-line option
--build-type determines which build types of the libraries are created. By default, this option is set to
minimal, meaning that only release builds are created. This may become an issue for developers who want to create debug builds of their projects with Visual C++ or GCC. Because these compilers automatically try to link against the debug builds of the Boost libraries, an error message will be displayed. In this case the option
--build-type should be set to
complete to generate both debug and release builds of the Boost libraries. This can take quite some time, which is why
complete is not the default.
Boost libraries that have to be compiled are made available on Windows with file names that contain version numbers and various tokens. They make it possible, for example, to tell whether a library has been built as a debug or release variant.
libboost_atomic-vc120-mt-gd-1_56 is such a file name. This library was built with Visual C++ 2013. It belongs to the Boost libraries 1.56.0. It is a debug variant and can be used in multithreaded programs. With the command-line option
--layout, bjam can be told to generate other file names. For example, if you set it to
system, the same file would be called
libboost_atomic. On Linux,
system is the default setting. If you want file names on Linux to be the same as those generated on Windows by default, set
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
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.