Wednesday 18 April 2012

Using QuantLib on the iPad: Part II - Build QuantLib


I have found most discussions about building QuantLib for the iPhone or iPad recommending to include the source code directly in an Xcode project and building it as part of the application.

Whilst this enables development to start quickly, it is restrictive in that you need to do this for every project that uses QuantLib and it makes it more difficult to upgrade versions. Building the QuantLib library as a framework enables better reuse and different versions can be built and swapped in and out of projects more quickly. Also, using the build system supplied with QuantLib (configure and autogen) guarantees that the libraries will be built correctly and include all the relevant dependancies.

The steps to build the framework to build the static libraries for each architecture, merge them and build the framework.

To build the static libraries:

  • "configure" the system to build the Armv6 libraries
  • "make" the Armv6 library using the Xcode arm-apple-darwin10-llvm-g++-4.2 compiler
  • "configure" the system to build the Armv7 libraries
  • "make" the Armv7 library using the Xcode arm-apple-darwin10-llvm-g++-4.2 compiler
  • "configure" the system to build the i386 libraries
  • "make" the i386 library using the default Xcode compiler

Between each build a "make clean" is performed to clear down the previously built objects (this ensures that we don't have any problem with dependancies in the next build).

Once the libraries are built, they are merged together into a fat (multi-architecture) library containing the Arm and i386 libraries in using lipo.

The framework directory structure and manifest is then created and the fat library and header files are copied.

To simplify this, I created a script that is available on github under the quantlib-on-iOS project.

To use it:

  • Download the QuantLib source code and unpack it
  • Copy the script buildql.sh into the QuantLib source code root directory
  • Configure the boost directory variable in the script
  • Configure the number of concurrent jobs to run in the script (usually 1+number of cores)
  • Run ./buildql.sh

At this point it may take between 30 minutes to over 1 hour to build, depending on the performance of your machine as QuantLib is built 3 times to create each architecture.

The QuantLib framework is created in the "framework" subdirectory which can then be included in iOS applications link libraries.



The previously built Boost framework also needs to be included as it is a QuantLib dependancy.

I have tested the framework on both the simulator and on an iPad and the application runs fine. I have not yet validated it against an App Store submission.

This is an example of a simple bond calculation being called from the QuantLib framework which I will go into more detail in the next post.


2 comments:

  1. Excellent post! Any reason to believe Apple wouldn't approve an app built to include/use this?

    ReplyDelete
  2. There should be no reason. My next application to the Apple Store will use Quantlib and I expect it to pass validation as it complies to the rules.

    ReplyDelete