Skip to content
Latchkey

b2: Boost.Build for Building Boost and B2 Projects

b2 drives Boost.Build (B2) using a Jamfile project description, most commonly to compile the Boost C++ libraries after running bootstrap.sh.

Building Boost from source in CI means bootstrap.sh then b2. The same engine builds any B2 project. Key knobs are the toolset (compiler), variant (debug/release), and -j.

What it does

b2 reads Jamfile/Jamroot project files and builds the requested targets with the chosen toolset and variant. For Boost itself, bootstrap.sh first builds the b2 engine and writes project-config.jam, then b2 compiles and optionally installs the libraries.

Common usage

Terminal
./bootstrap.sh --prefix="$PWD/stage"
./b2 -j$(nproc) toolset=gcc variant=release
./b2 --with-system --with-filesystem install
./b2 -j4 link=static runtime-link=static

Options

Property / flagWhat it does
toolset=<name>Compiler toolset: gcc, clang, msvc
variant=<v>debug or release
-j <N>Parallel job count
link=static|sharedBuild static or shared libraries
--with-<lib>Build only the named Boost library
--prefix=<path> (bootstrap)Install prefix set during bootstrap
installInstall headers and built libraries to the prefix

In CI

Run ./bootstrap.sh before b2 to build the engine, then ./b2 -j$(nproc). Use --with-<lib> to build only the libraries you need, since a full Boost build is slow. Set toolset explicitly to match the compiler you installed rather than relying on autodetection.

Common errors in CI

"./b2: No such file or directory" means bootstrap.sh was not run yet. "error: No toolsets are configured" or "notice: could not find main target" points at a missing or misdetected toolset; pass toolset=gcc explicitly. "You have not written a custom user-config.jam" warnings are usually benign. A link failure with "cannot find -lboost_..." downstream means the needed --with-<lib> was not built or installed.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →