Simple Guide to Installing Boost on Mac OS X

Boost

Do you want to get the Boost C++ libraries compiled for use with XCode on Mac OS X? I struggled to get it working so I’ve decided to write this mini-guide so I don’t forget. A little word of warning, the installation process requires a bit of command line kung-fu, if you are not comfortable using the terminal then you should read up on that first. This guide is correct at the time of writing using Boost version 1.39.0 on Mac OS 10.5.7. Are you ready? Then let’s go…

  1. The first thing to do is to download the Boost distribution from the Boost downloads page.
  2. Unpack the archive somewhere sensible, I’d suggest the desktop. Don’t do it where the absolute folder path will have any spaces in the name e.g. “/users/matt/code/bad folder/”, this will prevent the install script from working later. I found this out the hard way.
  3. Next open a terminal window and navigate to the Boost root folder you just unpacked, it will be called “boost_1_39_0″ if you are using the current version. If it’s on your desktop you will need to use “cd /users/username/desktop/boost_1_39_0“. We refer to this path in future as the $BOOST_ROOT
  4. Next run the bootstrap script by typing “./bootstrap.sh“. This configures the install tools for your environment. Check it for error messages, this is where I found out my path was bad.
  5. If you run the “ls” command you should now have an executable called bjam.
  6. To compile Boost, type “./bjam architecture=combined” and press enter, this will build Universal (x86 and PowerPC compatible) libraries.
  7. Make a cup of coffee and wait while the libraries build.

That’s all there is to it. You should end up with a load of .dylib and .a library files at the path $BOOST_ROOT/stage/lib. There’s a more detailed explanation of all this on the Boost Getting Started on Unix Variants page if you get stuck or something goes wrong. Your next job is to configure an XCode project to build with Boost, which is outside the scope of this article. I may do a post on it in the future.

Update, Saturday, 12 December 2009: The latest version of Boost is 1.41 and it installs on Snow Leopard without any problems following the instructions in my guide. Thanks.

13 Responses to “Simple Guide to Installing Boost on Mac OS X”

  1. moka says:

    Hey, Thanks for your guid, that helped me alot. one additional thing I had to do though ( I am a terminal noob ) was to allow the execution of bootstrap.sh like this:
    chmod +x bootstrap.sh

    this might be trivial, but it took me some time to stumble upon that command. Otherwise thanks for that guide!

    • Matt says:

      Hi moka. Glad to have helped. You make a good point about the file privileges problem. If you have a root account setup you can use sudo to run the script, like so:-

      sudo ./bootstrap.sh

      You then get asked for the root user password and it will run. I will update the guide to include this. Here’s a quick guide to setting up root on Leopard that I found. http://bit.ly/1UrWZv

  2. [...] if you are brave enough to do some 3D. It is built on top of the Boost libraries (See my previous post on Installing Boost), so if you need advanced stuff like threads you can get those without too much [...]

  3. Ryan says:

    Has anyone tried this on Snow Leopard? The “architecture=combined” parameter causes everything to fail.

    • Matt says:

      No, I’ve not tried it yet. Reading around on the forums it does seem to be a problem. Not sure what it is yet. When I work it out I’ll update the article. If anyone finds a solution, let me know in the comments.

      Thanks for pointing this out.

  4. [...] on my hands at the moment, I thought I’d get back into playing around with Boost. Since my Simple Guide to Installing Boost on Mac OS X article was published we have had a few new releases of Boost, and more importantly a whole new [...]

  5. moka says:

    Hey,

    I tried the sudo version too but it didn’t work for some reason, maybe I did something wrong though!

  6. Matt says:

    Hmm strange, have you definitely setup a root account? Otherwise I don’t think sudo will work. You also need to use the password you set for the root account, not your current login password. Like most Unix commands it doesn’t give you an error when it fails, which is a pain. I might give the instructions another run through to see if I missed anything.

  7. moka says:

    no i guess that was the problem. Another question, do you know if it is possible to compile the files into one boost.framework? thank you!

  8. Matt says:

    I think it might be. A few people have recommended just dumping the source into your own xcode project and compiling it in. I would advise against it though because boost is pretty bit! If you link against the dynamic dylibs you need to copy those into your executable bundle which is the same as you’d need to do with a framework.

  9. moka says:

    hmm okay, I am genereally new to frameworks and all the c++ library types, so this might be a stupid question. it’s not possible to compile it all into one framework, so I could simply include boost.framework in my xCode Project?

  10. Matt says:

    Most of boost is compiled inline from the headers. You only need the library’s to link against for threads, regex and a couple of other things. Any boost.framework would need to include everything in boost to be useful, that would be all the libraries and all the headers which would lead to quite large apps.

    In the end, after you’ve got the libraries compiled you just need to include the one’s you need to get your app to link and make sure there’s a build step to copy them over, it’s almost the same as using a framework, except the copy isn’t done automatically during the build.

  11. moka says:

    ah okay that makes sense. thanks

Image | WordPress Themes