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

This is an old version of boost. Click here for the latest version's documentation home page.
PrevUpHomeNext

Prebuilt targets

We've just learned how to use libraries which are created by Boost.Build. But some libraries are not. At the same time, those libraries can have different versions (release and debug, for example), that we should select depending on build properties. Prebuilt targets provide a mechanism for that. Jamfile in util/lib2 can contain:

lib lib2
    : 
    : <file>lib2_release.a <variant>release
    ;

lib lib2
    : 
    : <file>lib2_debug.a <variant>debug
    ;

This defines two alternatives for target "lib2", and for each one names a prebuilt file. Naturally, there are no sources. Instead, the <file> feature is used to specify the file name. Which alternative is selected depends on properties of dependents. If "app" binary should use "lib2", we can write:

exe app : app.cpp ../util/lib2//lib2 ;

If we build release version of "app", then it will be linked with "lib2_release.a", and debug version will use "lib2_debug.a". Another important kind of prebuilt targets are system libraries — more specifically, libraries which are automatically found by the compiler. E.g. gcc uses "-l" switch for that. Such libraries should be declared almost like regular ones:

lib zlib : : <name>z ;

We again don't specify any sources, but give a name which should be passed to the compiler. In this example, and for gcc compiler, the "-lz" option will be added. Paths where library should be searched can also be specified:

lib zlib : : <name>z <search>/opt/lib ;

And, of course, two variants can be used:

lib zlib : : <name>z <variant>release ;
lib zlib : : <name>z_d <variant>debug ;

Of course, you'll probably never in your life need debug version of zlib, but for other libraries this is quite reasonable.

More advanced use of prebuilt target is described in a FAQ entry.


PrevUpHomeNext