Here is the problem: GDAL is a fantastic open source library designed to manage complex GIS data, both raster as well as vector. It is fully compiled for the Mac OS (courtesy of William Kyngesburye) and other platforms but not for iOS.
Browsing the net you can find bits and pieces of (relatively old) information on the topic of creating an iOS library, starting with the famous script from pseudogreen which was written over 3 years ago. There are also bits and pieces on stack-overflow such as GDAL / OGR on the iPhone which provide additional information.
This article is meant to cover all the steps I took which led me to a fully functional integration of GDAL/OGR in a simple iOS app using iOS6 and XCode 4.5.5
Note
This response was written some time ago and mo longer works with Xcode 6 and up. Please check this link for a more current answer to this problem.
Introduction
Incorporating GDAL into your iOS app is a 5 steps process:
Downloading GDAL
GDAL is a C++ open source library which can be downloaded from the www.gdal.org web site. At the time of writing the latest version is 1.9.0. You should download the latest stable version if possible.
Run the script to compile GDAL for iOS and the simulator
In order to use GDAL in your iOS project you need to compile the source code as a static library (.a). With the latest iOS6-supported architecture you should create the static library for the following architectures:
Base script to build for 1 architecture
The following script, which is adapted from pseudogreen's does the trick of compiling the source code for a single architecture.
Copy paste this code into a text editor and save it as file with .sh extension: for instance build_gdal_ios.sh.
To use it copy the script into the directory where you downloaded the gdal source code and run it as follows:
To build the library for the simulator:
To build it for the device:
You can also type
sh build_gdal_ios.sh -h
to get the help.Notice that this script has a few default parameters which you can change to reflect your preferences or changes in the SDK or LLVM Apple compiler:
And now building for multiple architectures
Using the preceding script (
build_gdal_ios.sh
) allows you to build one architecture at a time... You need to compile for 3 and then bring all these libraries together under one single static library file.The following script allows just that (save it to another name such as build_gdal_all_ios.sh):
After running this script you will have your libraries saved in your ${HOME}/Documents/GDALLibrary directory in subfolders:
You can now use the executable lipo (for liposuction) to join the 3 libraries into a single one like so:
... And you're done...
Add the static library to your XCode project
This step is rather straightforward:
Build your code. All should compile without trouble.
Start coding
There is a trick here: you are using a C++ library (and header files) in an Objective-C environment. If you include one of the GDAL header files into a .m file XCode will complain about the C++ syntax.
Here you have two solutions:
At one point I will be posting some GDAL code samples... but later...