How can I use the GNU Scientific Library in an iOS application?
I tried following this tutorial: http://www.os-scientific.org/devel/gslxcode/index.html. But it seems not to work for iOS this way, only for OS X. After I added the GSL source code to XCode using an "external build system", XCode wants to build the target of that GSL subproject for the OS X SDK instead of the iOS SDK.
Ok! The configuration that worked for me:
It wasn't easy, but these are the steps I took to get it working...
1) Download and extract latest GSL
2) In the gsl directory,
./configure --disable-shared --disable-dependency-tracking CFLAGS="-DGSL_C99_INLINE -g -O2"
3) Create a Cocoa Touch Static Library project in Xcode.
4) Copy the following headers into the project:
config.h, build.h, gsl_machine.h
5) Find the function(s) you want to use in your project. Copy those
.c
files into your project.6) Then track through that function to see what other functions it calls, all the way down to the bottom.
7) Copy into your project all of the
.c
files those functions are in.8) Copy into your project all of the
.h
files needed for those function definitions.9) There is a more elegant way to do this, but for me, I just took the simple route and changed the
#include <gsl/xxxxx.h>
statements to#include "xxxxxx.h"
. Comment out any#include
s that you don't actually need.10) Any function you don't need in those
.c
files, you can remove them in order to reduce the number of other includes you need to use. You can either just delete them, but I recommend putting#if 0
and#endif
around them instead. Just in case you missed something and need to include them later.11) Build and check for errors. If you're missing a function, include the
.c
file for that function, rinse, repeat.I needed to include
gsl_cdf_tdist_P()
for my project, and when I tracked down through all of the method calls, this is the list of all of the functions needed. (any function with an * after is one that has already been encountered, so I didn't need to track down through it):I'm not sure if there is a better way but here is what I do: I created a new "Cocoa Touch Static Library" project on XCode and put in all the necessary GSL source files I needed. Set the active scheme to "iOS device" if you want to run it on iPhone (otherwise, it will only work on iPhone simulator). Then build the project and you'll get your static GSL library that works on iPhone!
Small devices running iOS are 32-bit systems. You will need to rebuild the Gnu Science Library (GSL) for 32-bit machines by configuring the make process as follows: ./configure CFLAGS="-arch i386", then make and link the new library file to your project according to the tutorial in your first attempt.
A revision of the above statement: That advice works fine in getting a build that works for the iOS simulator, but it's not clear that GSL can even be successfully built for the ARMv7 architecture without changing the code base. If it is at all possible, it would appear that one needs a different tool chain for building GSL from the one provided.