Boost C++ Libraries with iOS

Implementation of frequent programming tasks beyond the Standard C++ Library such as asynchronous I/O, threading, serialization, date and time, smart pointers, delegate functions etc. – while being compatible to the STL – is the power of the Boost C++ Library. In your iOS projects it enables you to write truly platform independent C++ code which relies on a high performance, industry-strenght basis.

Unfortunately no pre-built binaries of the several compilation-needed components of boost exist. Furthermore the build process is abound with complier switches, linker switches and path variables. The threesome of Apple’s iPhone and Simulator SDKs, GNU’s g++ and Boost’s bjam results in a scary hell. E.g. you will have to learn that with Darwin not always the scientist is meant.

To the rescue Pete Goodliffe has created an excellent script to build a framework for use with the iPhone. It works like charm: Within a 1-2 hours you’ll have roughly 47MBytes of arm7, arm6 and i386 libraries and all that remains is to add the framework itself to your project’s direct dependencies in XCode and specify the path to the framework in the “Framework Search Path” settings.

Finally you can concentrate on the things you want: E.g. if you feel the NSArray syntax is too bloated for your algebra, use boost::array instead. It comes with serialization as well:

#include <boost/array.hpp>
#include <boost/serialization/array.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <iostream>
#include <fstream>
#include <boost/foreach.hpp>
boost::array<int, 7> dataArray;
std::ifstream inputFile("data.txt");
boost::archive::text_iarchive inputArchive(inputFile);
inputArchive >> dataArray;
int median = dataArray[3];
BOOST_FOREACH(int value, dataArray)
{
   NSLog(@"%d", value);
}

One Response to “Boost C++ Libraries with iOS”

  1. JB Says:

    Great guide – thanks!

    Just because the framework is 47MB, doesn’t mean an App will weigh in 47MB heavier does it?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: