For a recent project I’ve had to compile the Boost C++ library for the iPhone. Much of the Boost library is header files so they are fine as nothing needs to be done, they just get copied into place, but the bits which do need compiling are a bit trickier. So I thought I’d share my experiences here.
First you need to download Boost (I went for version 1.40) from http://www.boost.org. Then you need to edit some of the Boost.Jam configuration. This involves creating a user-config.jam file in your home directory like so:
~/user-config.jam
1234567891011
using darwin : 4.2.1~iphone
: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6
: <striper>
: <architecture>arm <target-os>iphone <macosx-version>iphone-3.0
;
using darwin : 4.2.1~iphonesim
: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386
: <striper>
: <architecture>x86 <target-os>iphone <macosx-version>iphonesim-3.0
;
Then edit tools/build/v2/tools/darwin.jam and add in the following under the macosx-versions variable:
It’s worth noting that at this stage everything will compile for the simulator but not for the device. This is because the device is missing two header files – bzlib.h and crt_externs.h. To make it compile for the device simply copy these files from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/include/ into your Boost folder and then everything should compile fine. I have no idea why Apple have omitted these header files from the device. The libraries are there, just the header files missing. I’ve created a bug on Radar for this, so please also do the same if you encounter this problem such that Apple will listen and include them.
That installs the files in ~/Developer/Platforms/iPhone(OS|Simulator).platform/Developer/SDKs/iPhone(OS|Simulator)3.0.sdk/usr which was where I wanted mine to go, but feel free to change that to wherever you want the libraries to end up. I did it this way because I created a custom SDK and then include that from iPhone projects within XCode.
boost-1.42:
Since Boost has been updated, I thought I’d extend this article to explain how to compile boost-1.42 for the iPhone. Boost themselves have gone a long way to do everything for you now, so there’s much less that needs to be done. You now need to do this:
~/user-config.jam
1234567891011
using darwin : 4.2.1~iphone
: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv7 -mthumb -fvisibility=hidden -fvisibility-inlines-hidden
: <striper>
: <architecture>arm <target-os>iphone <macosx-version>iphone-3.1.3
;
using darwin : 4.2.1~iphonesim
: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -fvisibility=hidden -fvisibility-inlines-hidden
: <striper>
: <architecture>x86 <target-os>iphone <macosx-version>iphonesim-3.1.3
;
Then edit tools/build/v2/tools/darwin.jam and add in the following under the macosx-versions variable: