Creating a library in Boost Build is easy; it's doubly so when using Macaroni.
Pulling in a library like that is similarly easy - just use the “use-project” rule and reference the jamroot.jam file of the dependency.
However, the best practice of referencing a Boost library itself has confused me for awhile. There is not jamroot.jam file for each project, and referencing the main jam file at the root of the Boost distribution folder doesn't lead to happy results either. So how do you do it?
It turns out to be really simple.
First, make sure to set an environment variable named BOOST_ROOT to the absolute path of the unzipped Boost distribution directory.
Then, create a file called site-config.jam in your home directory, containing this:
using boost
: 1.52
;
For awhile, I kept thinking I needed to actually put the path to Boost in this file. Nope! That actually causes all hell to break lose in Windows and for things to generally not work (in Linux nothing bad seems to happen, but since doing it the way I'm suggesting now works in both OSes it might be better to keep things consistent).
With these two steps out of the way, it's easy to include the Boost libraries:
import boost ;
boost.use-project ;
exe recreate
: ../src/Main.cpp
/boost//headers
/boost//system
/boost//filesystem
;
This project will build Main.cpp, which uses the Boost FileSystem and System library as dependencies. It will even build these libraries if they're missing! It also adds the Boost headers to the include path while building Main.cpp. Easy, no?
On a side note, I actually knew about this method years ago but ran into trouble using it when building complex projects with Macaroni, when a library would depend on another library which depended on Boost. I think in retrospect, this was due to some problem I had created. The good news is, I recently changed Macaroni to use this method and found that it jam files which build correctly on both Windows and Linux, even with complex projects using multiple dependencies.