In case you’ve never heard of it before, Boost is a set of peer reviewed libraries for C++. They provide a lot of features that are sorely missing from the standard C++ libraries and are probably the closest C++ developers have to a standard development toolkit. In fact, Boost is so useful that a number of the projects were included in the C++11 standard.
To install the official upstream version of boost you need to build it using bjam. This isn’t that hard but it’s not as simple as just installing a package. The good news is that most Linux distributions include native package installers. Windows developers are covered by the wonderful installer packages that are maintained by BoostPro.
The downside to using these packages is that you are tied in to the release cycle of the package maintainer. Often, Linux packages can be 2, 3, 4 or even more releases behind the official upstream. BoostPro does a pretty good job of keeping packages up-to-date but it’s still normally a release behind. Also, BoostPro may not have a package for your compiler or version.
The answer, of course, is to build Boost yourself but this can be a daunting prospect if you’ve never done it before. This article will cover building Boost for Windows for use with Visual Studio (it may be followed up by a similar article explaining how to build Boost for Linux).
Why am I focusing on Windows? A few reasons:
- I actually need a Windows installation so now is a good a time as any to write this guide.
- BoostPro doesn’t currently have an installer for Visual Studio 2012.
- My experience is that building Boost on Windows is that it’s generally more problematic that doing so on Linux.
- Linux developers are generally more used to messing around with the lower-levels of compilers, linkers and make files and so are less likely to find building Boost from scratch a daunting task.
So, here is a simple step-by-step guide to building Boost for Windows.
- Download boost and extract it somewhere.
- Open the Visual Studio command prompt (NOT cmd.exe).
- Change directory to the root folder of Boost.
- Run “bootstrap”, which will prepare the Boost Build engine.
- Run “.b2”, which will start building the Boost libraries.
- Go and have a few cups of tea (you’ll be waiting quite a while).
- Add Boost root folder to the compiler’s standard include path.
- Add <rootpath>/stage/lib to the compilers standard library path.
- If all went well you should now be able to build against Boost.
NB. this was tested using Boost 1.52 and later or newer versions may require different steps. Please consult the official Boost installation documentation for more details.