Thursday, 10 December 2009

Boost on the iPhone

This is the simple way to get Boost into your iPhone code.

I've been porting a large C++ project to the iPhone. It uses the excellent Boost libraries. Building Boost for the iPhone is not impossible, just a bit of a pain in the arse.

There are a number of good examples of how to do this online, for example the Backstage blog entry here and Matt Galloway's blog here. They are useful hints that help you work past the impenetrable Boost Build documentation.

However, the story does not end here. Those instructions allow you to build a set of libraries for the simulator, or for the iPhone OS. But not both. This means that your Xcode project setup gets fiddly with different link paths for the different targets.

You can solve this by creating a "universal" fat library. The lipo tool can be used to shunt the individual libraries together. Not tricky, just another step.

Now, for bonus points it would be sweet to construct a "Framework" for the Boost libraries, allowing you to use them in Xcode like any other iPhone framework. I've already blogged on how to do this here.

Of course, if you were sensible, you'd wrap this up in a script so that anyone can use it. A script a bit like this one.

I've set up a Gitorious project for this script. Feel free to use it.


Ken said...

Hi Pete,

Thanks for the Boost framework build script for iPhone! I finally got it working, but I ran into a couple of issues.

I found four places where the SDK version number "3.0" was hard-coded into the script. I had set IPHONE_SDKVERSION to 3.1.2 though, and the script failed when linking the thread library.

I changed those 3.0 references to $IPHONE_SDKVERSION, and then the build went off smoothly.

When trying to build in XCode, however, at first it could not find the header files. This was due to the fact that the Boost library was named with a capital "B". I tried manually renaming it, and that let me compile, but the link failed to find the Boost framework (presumably due to some internal name with "B" still).

I change the value of the FRAMEWORK_NAME variable in to "boost" with a lowercase "b", and rebuilt everything from scratch.

That did the trick. I am wondering if you built on a file system that is case insensitive (mine is case sensitive).

Anyway, I thought I would pass along this information to you to perhaps update the script for others.

Thanks again for the great script. I am sure it saved me a few hours of time!

Steve said...

Thanks for a great script. You saved me loads of time building boost 1_45_0.