| 1 | = Build boost on MinGW = |
| 2 | Oct 19 2012 |
| 3 | |
| 4 | [[Image(htdocs:images/boost/boost-logo.png, alt="boost c++ library", align=center)]] |
| 5 | |
| 6 | Building the boost binaries is one of the optional steps for building the [http://ogre3d.org Ogre] graphics engine from source. I ran into a few difficulties building the [http://boost.org boost] binaries on MinGW. |
| 7 | |
| 8 | '''Assumptions:''' You're familiar with Windows & Unix utilities, shell scripting ( bash & cmd ), know about command line compilation and are generally fearless, like a lion. |
| 9 | |
| 10 | Here's my development setup: |
| 11 | ||Platform||Windows 7 x64|| |
| 12 | ||Toolchain||mingw gcc on msys which you can get [http://www.mingw.org/ here].|| |
| 13 | ||gcc version||4.7.0 - get this with mingw|| |
| 14 | ||Boost version||1.51 from [http://boost.org boost.org]|| |
| 15 | |
| 16 | '''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. |
| 17 | |
| 18 | '''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. |
| 19 | |
| 20 | '''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. |
| 21 | |
| 22 | 1. Get boost 1.51 from [boost.org boost.org]. |
| 23 | 1. Put it in `~/external/boost`, so your boost source root will be `~/external/boost/boost_1_51_0` |
| 24 | 1. We're going to use this a few times in the future, so set it as an environment var. |
| 25 | {{{#!bash |
| 26 | export BOOST_SRC_ROOT=~/external/boost/boost_1_51_0 |
| 27 | cd $BOOST_SRC_ROOT |
| 28 | cd tools/build/v2 |
| 29 | }}} |
| 30 | 1. To build the binary parts of boost, we first need to build the boost build system. |
| 31 | {{{#!bash |
| 32 | ./bootstrap.sh --with-toolset=mingw |
| 33 | }}} |
| 34 | Note that the documentation on the boost wiki is wrong. You <strong>_must_</strong>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: |
| 35 | {{{#!bash |
| 36 | $ sh bootstrap.sh |
| 37 | Bootstrapping the build engine with toolset gcc... |
| 38 | Failed to bootstrap the build engine |
| 39 | Consult 'bootstrap.log' for more details |
| 40 | $ cat bootstrap.log |
| 41 | ### |
| 42 | ### Using 'gcc' toolset. |
| 43 | ### |
| 44 | rm -rf bootstrap |
| 45 | mkdir bootstrap |
| 46 | 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 |
| 47 | builtins.c:33:23: fatal error: sys/wait.h: No such file or directory |
| 48 | compilation terminated. |
| 49 | execunix.c:17:26: fatal error: sys/resource.h: No such file or directory |
| 50 | compilation terminated. |
| 51 | fileunix.c:98:17: fatal error: ar.h: No such file or directory |
| 52 | compilation terminated. |
| 53 | }}} |
| 54 | 5. Set output and installation directories and build. |
| 55 | {{{#!bash |
| 56 | export BUILD_OUTPUT_DIR=~/build/output |
| 57 | export BUILD_INSTALL_DIR=~/build/install |
| 58 | export BOOST_VERSION=1_51_0 |
| 59 | export BOOST_BUILD_DIR=$BUILD_OUTPUT_DIR/boost_$BOOST_VERSION |
| 60 | export BOOST_INSTALL_DIR=$BUILD_INSTALL_DIR/boost_$BOOST_VERSION |
| 61 | mkdir -p $BOOST_BUILD_DIR |
| 62 | mkdir -p $BOOST_INSTALL_DIR |
| 63 | ./b2 toolset=gcc --prefix=$BOOST_BUILD_DIR/build install |
| 64 | export PATH=$PATH:$BOOST_BUILD_DIR/build/bin |
| 65 | }}} |
| 66 | 1. '''mingw specific:''' Comment out the following line ( around line 486 ) in tools/python.jam: |
| 67 | `python-cmd = "$(python-cmd)" ;` It's within this if block: |
| 68 | {{{#!python |
| 69 | if [ version.check-jam-version 3 1 17 ] || ( [ os.name ] != NT ) |
| 70 | }}} |
| 71 | 7. Now that the boost build system is built and installed, time to build the actual boost library binaries. |
| 72 | {{{#!bash |
| 73 | cd $BOOST_SRC_ROOT |
| 74 | b2 --build-dir=$BOOST_BUILD_DIR toolset=gcc --prefix=$BOOST_INSTALL_DIR install 2>&1 | tee $BOOST_BUILD_DIR/build.log |
| 75 | }}} |
| 76 | |
| 77 | That will build static and shared non-debug multi-threaded variants of the libraries. To build all variants, pass the additional option, `--build-type=complete1 |
| 78 | 8. 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`. |
| 79 | '''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. |
| 80 | |
| 81 | |
| 82 | == Posix Build Specifics ( Ubuntu LTS 12.04 ) == |
| 83 | To get boost to build without errors under Ubuntu LTS 12.04, you need to install the following additional libraries via apt-get: |
| 84 | |
| 85 | 1. python-dev |
| 86 | 1. libbz2-dev |
| 87 | |
| 88 | '''Update:''' Added posix build info. |
| 89 | |
| 90 | '''Update 2012-10-30:''' Fixed paths and added note to comment out line 489 in `tools/python.jam` |