Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Click here to view the latest version of this page.
PrevUpHomeNext

Chapter 20. Tutorial

Table of Contents

Hello, world
Properties
Build Requests and Target Requirements
Project Attributes
Project Hierarchies
Libraries and Dependent Targets
Library dependencies
Static and shared libaries
Conditions and alternatives
Prebuilt targets

Hello, world

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

exe hello : hello.cpp ;

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

bjam release

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

exe hello2 : hello.cpp ;

Now we can build both the debug and release variants of our project:

bjam debug release

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

bjam --clean debug release

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

bjam hello2
bjam --clean hello2

PrevUpHomeNext