A Simpler Way to Build Boost
Thursday December 21, 2017 09:32:55

Yesterday I wrote a post about using a lame Python script to rename the Boost binaries built by Bjam. Today's post is how such a script is completely unnecessary; you can just tell Boost to name the files differently.

I've been using the option –build-type=complete to build the Boost libraries for years. It basically tells it to build all of the different variations possible for a library and a given compiler, which helped me in my previous life when I used nothing but Boost build (so the tree was organized as “library/variants”). However in the modern Cenv era where I use prefix paths for each build variation which then contain libraries (so the tree is “variant/libraries”) there's no need to do this.

So instead when calling b2 pass in –layout=system which gets Boost to avoid all of it's squirrelly naming conventions, which works just fine since the resulting binary will be the only file for a given Boost library sitting in a cenv.

SO: the final install process looks like this:

cd boost-directories
bootstrap.bat
cenv set win64-debug
b2.exe --clean-all
b2.exe --stagedir="%CGET_PREFIX%" --toolset=msvc-14.1 address-model=64 debug link=shared --layout=system stage -j8 --with-system

First off, win64-debug is a cenv I created with cenv init win64-debug -DCMAKE_GENERATOR_PLATFORM:none=x64 -DCMAKE_BUILD_TYPE:none=Debug. The toolchain arguments for cenv init go to CMake and tell it to build for 64 bit (ideally it would tell it to force builds for debug, but it doesn't do that on MSVC++ for reasons I won't get into).

When I run b2.exe, this toolchain info is translated to bjam-ease, with CMAKE_GENERATOR_PLATFORM=x64 turning into address-model=64. So for any given cenv you'll probably need to Google the translation from CMake to Boost Build to make sure your builds agree.

Finally, –with-system tells Boost to build the “system” library. To see the possible libraries use b2 –show-libraries. It's also possible to specify multiple –with args on the command line.

So: voilĂ ! Assuming you mucked with Cmake to make it build the most recent version of Boost you should be good to go. This is about as simple as I've ever gotten the process of using the Boost libraries to be.

Note that the environment variable BOOST_ROOT still needs to be set; otherwise, we'll have to copy the boost headers into our cenv. That's as simple as copying the boost directory into the include directory of the cenv, but since it takes up 114 MB and I seem to be constantly running out of the paltry 256gb of disk space I have on the solid state drives I'm using I prefer not to.

Note: cget also has some interesting built in support for building and installing Boost, so you may want to look into using that. However it requires copying an entire distribution of all the Boost libraries to a temporary directory before it even does anything- which is involves an extra 524 MB!!- which may be a deal breaker if you're as perpetually low on disk space as I am.





<---2018-12-09 09:32:55 history 2017-12-20 09:32:55--->



-All material © 2007 Tim Simpson unless otherwise noted-