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

PrevUpHomeNext

Header-only libraries

In modern C++, libraries often consist of just header files, without any source files to compile. To use such libraries, you need to add proper includes and possibly defines to your project. But with a large number of external libraries it becomes problematic to remember which libraries are header only, and which ones you have to link to. However, with Boost.Build a header-only library can be declared as Boost.Build target and all dependents can use such library without having to remeber whether it is a header-only library or not.

Header-only libraries may be declared using the alias rule, specifying their include path as a part of its usage requirements, for example:

alias my-lib
    : # no sources
    : # no build requirements
    : # no default build
    : <include>whatever ;

The includes specified in usage requirements of my-lib are automatically added to all of its dependants' build properties. The dependants need not care if my-lib is a header-only or not, and it is possible to later make my-lib into a regular compiled library without having to that its dependants' declarations.

If you already have proper usage requirements declared for a project where a header-only library is defined, you do not need to duplicate them for the alias target:

project my : usage-requirements <include>whatever ;
alias mylib ;

PrevUpHomeNext