Build boost on MinGW

Oct 19 2012

boost c++ library

Building the boost binaries is one of the optional steps for building the Ogre graphics engine from source. I ran into a few difficulties building the boost binaries on MinGW.

Assumptions: You're familiar with Windows & Unix utilities, shell scripting ( bash & cmd ), know about command line compilation and are generally fearless, like a lion.

Here's my development setup:

PlatformWindows 7 x64
Toolchainmingw gcc on msys which you can get here.
gcc version4.7.0 - get this with mingw
Boost version1.51 from

Note: I build all default libraries in boost, rather than just the bare minimum required for Ogre. Takes a couple of hours on my circa 2009 Intel Core i7 laptop with 4GB RAM & Seagate Momentus XT SATA II HDDs.

Note 2: I've learned the hard way that using a tilde i.e. ~ in args that take a path to b2 under mingw, result in a directory with the name ~ being created in the current directory into which relevant files are placed. So, don't pass a ~ to b2.

Note 3: This one's slightly "duh", but readlink will fail silently if you pass it a non-existent link, file or path. So, I pre-create directories where needed.

  1. Get boost 1.51 from [].
  2. Put it in ~/external/boost, so your boost source root will be ~/external/boost/boost_1_51_0
  3. We're going to use this a few times in the future, so set it as an environment var.
    export BOOST_SRC_ROOT=~/external/boost/boost_1_51_0
    cd tools/build/v2
  4. To build the binary parts of boost, we first need to build the boost build system.
    ./ --with-toolset=mingw
    Note that the documentation on the boost wiki is wrong. You must pass the toolset you want to use using the above syntax for boost build to build in mingw. Simply passing gcc or mingw will cause the build to fail with something like this in the error log:
    $ sh
    Bootstrapping the build engine with toolset gcc...
    Failed to bootstrap the build engine
    Consult 'bootstrap.log' for more details
    $ cat bootstrap.log
    ### Using 'gcc' toolset.
    rm -rf bootstrap
    mkdir bootstrap
    gcc -o bootstrap/jam0 command.c compile.c constants.c debug.c function.c glob.c hash.c hdrmacro.c headers.c jam.c jambase.c jamgram.c lists.c make.c make1.c object.c option.c output.c parse.c pathunix.c regexp.c rules.c scan.c search.c subst.c timestamp.c variable.c modules.c strings.c filesys.c builtins.c pwd.c class.c native.c md5.c w32_getreg.c modules/set.c modules/path.c modules/regex.c modules/property-set.c modules/sequence.c modules/order.c execunix.c fileunix.c
    builtins.c:33:23: fatal error: sys/wait.h: No such file or directory
    compilation terminated.
    execunix.c:17:26: fatal error: sys/resource.h: No such file or directory
    compilation terminated.
    fileunix.c:98:17: fatal error: ar.h: No such file or directory
    compilation terminated.
  5. Set output and installation directories and build.
    export BUILD_OUTPUT_DIR=~/build/output
    export BUILD_INSTALL_DIR=~/build/install
    export BOOST_VERSION=1_51_0
    mkdir -p $BOOST_BUILD_DIR
    mkdir -p $BOOST_INSTALL_DIR
    ./b2 toolset=gcc --prefix=$BOOST_BUILD_DIR/build install
    export PATH=$PATH:$BOOST_BUILD_DIR/build/bin
  6. mingw specific: Comment out the following line ( around line 486 ) in tools/python.jam:

python-cmd = "$(python-cmd)" ; It's within this if block:

if [ version.check-jam-version 3 1 17 ] || ( [ ] != NT )
  1. Now that the boost build system is built and installed, time to build the actual boost library binaries.
    b2  --build-dir=$BOOST_BUILD_DIR toolset=gcc --prefix=$BOOST_INSTALL_DIR install 2>&1 | tee $BOOST_BUILD_DIR/build.log

That will build static and shared non-debug multi-threaded variants of the libraries. To build all variants, pass the additional option, --build-type=complete

  1. Check the build log for errors, you should have 12 failures due to missing unicode/uversion.h which you can safely ignore ( some internal check for optional stuff that should be warnings ). At the end of the build process, you should have the boost libs installed in ~/build/output/boost_1_51_0/lib and headers in the boost subdir under ~/build/output/boost_1_51_0/include/boost-1_51.

Note: Header files in mingw are in nested one level deeper than in posix builds i.e. in posix the dir structure looks like $BOOST_ROOT/include/boost and in mingw it's $BOOST_ROOT/include/boost-1_51/boost. So, when using boost in multi-platform builds like I do, you need to adjust your include path accordingly.

Posix Build Specifics ( Ubuntu LTS 12.04 )

To get boost to build without errors under Ubuntu LTS 12.04, you need to install the following additional libraries via apt-get:

  1. python-dev
  2. libbz2-dev

Update: Added posix build info.

Update 2012-10-30: Fixed paths and added note to comment out line 489 in tools/python.jam

Last modified 3 years ago Last modified on Feb 18, 2016, 7:28:26 PM