Boost C++ Libraries

PrevUpHomeNext

Chapter 2. Tutorial

Table of Contents

Hello, world
Properties
Project Hierarchies
Dependent Targets
Static and shared libraries
Conditions and alternatives
Prebuilt targets

This section will guide you though the most basic features of Boost.Build. We will start with the “Hello, world” example, learn how to use libraries, and finish with testing and installing features.

Hello, world

The simplest project that Boost.Build can construct is stored in example/hello/ directory. The project is described by a file called Jamroot that contains:

exe hello : hello.cpp ;

Even with this simple setup, you can do some interesting things. First of all, just invoking b2 will build the hello executable by compiling and linking hello.cpp . By default, the debug variant is built. Now, to build the release variant of hello, invoke

b2 release

Note that the debug and release variants are created in different directories, so you can switch between variants or even build multiple variants at once, without any unnecessary recompilation. Let us extend the example by adding another line to our project's Jamroot:

exe hello2 : hello.cpp ;

Now let us build both the debug and release variants of our project again:

b2 debug release

Note that two variants of hello2 are linked. Since we have already built both variants of hello, hello.cpp will not be recompiled; instead the existing object files will just be linked into the corresponding variants of hello2. Now let us remove all the built products:

b2 --clean debug release

It is also possible to build or clean specific targets. The following two commands, respectively, build or clean only the debug version of hello2.

b2 hello2
b2 --clean hello2


PrevUpHomeNext