Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Note</h1> <p>This response was written some time ago and mo longer works with Xcode 6 and up. Please <a href="http://www.hurtsdevelopment.com/blog/uncategorized/gdal-on-ios-it-works/" rel="nofollow">check this link</a> for a more current answer to this problem.</p> <h1>Introduction</h1> <p>Incorporating GDAL into your iOS app is a 5 steps process:</p> <ol> <li>Download the GDAL source code from the GDAL website</li> <li>Run the configure/build/install script given below</li> <li>Add the resulting static library into your iOS project along with the include files</li> <li>Link with additional libraries in your iOS project</li> <li>Start coding... the GDAL and OGR tutorials are good starting points</li> </ol> <h1>Downloading GDAL</h1> <p>GDAL is a C++ open source library which can be downloaded from the <a href="http://www.gdal.org" rel="nofollow">www.gdal.org web site</a>. At the time of writing the latest version is 1.9.0. You should download the latest stable version if possible.</p> <h1>Run the script to compile GDAL for iOS and the simulator</h1> <p>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:</p> <ul> <li>i386 for the simulator</li> <li>armv7 for iPhone 3GS to iPhone 4S</li> <li>armv7s for iPhone 5</li> </ul> <h2>Base script to build for 1 architecture</h2> <p>The following script, which is adapted from <a href="http://pseudogreen.org/blog/build_autoconfed_libs_for_iphone.html" rel="nofollow">pseudogreen</a>'s does the trick of compiling the source code for a single architecture.</p> <p>Copy paste this code into a text editor and save it as file with .sh extension: for instance build_gdal_ios.sh.</p> <p>To use it copy the script into the directory where you downloaded the gdal source code and run it as follows:</p> <ul> <li><p>To build the library for the simulator:</p> <pre><code>`sh build_gdal_ios.sh -p "location where you want to save the resulting files" simulator` </code></pre></li> <li><p>To build it for the device:</p> <pre><code>`sh build_gdal_ios.sh -p "location where you want to save the resulting files" -a "architecture" device` </code></pre></li> </ul> <p>You can also type <code>sh build_gdal_ios.sh -h</code> to get the help.</p> <pre><code> #!/bin/bash ################################################################################ # # Copyright (c) 2008-2009 Christopher J. Stawarz # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # ################################################################################ # Disallow undefined variables set -u default_gcc_version=4.2 default_iphoneos_version=6.0 default_macos_version=10.8 default_architecture=armv7 default_prefix="${HOME}/Documents/iOS_GDAL" GCC_VERSION="${GCC_VERSION:-$default_gcc_version}" export IPHONEOS_DEPLOYMENT_TARGET="${IPHONEOS_DEPLOYMENT_TARGET:-$default_iphoneos_version}" export MACOSX_DEPLOYMENT_TARGET="${MACOSX_DEPLOYMENT_TARGET:-$default_macos_version}" DEFAULT_ARCHITECTURE="${DEFAULT_ARCHITECTURE:-$default_architecture}" DEFAULT_PREFIX="${HOME}/Documents/iOS_GDAL" echo Default architecture: $DEFAULT_ARCHITECTURE usage () { cat &gt;&amp;2 &lt;&lt; EOF Usage: ${0##*/} [-ht] [-p prefix] [-a arch] target [configure_args] -h Print help message -p Installation prefix (default: \$HOME/Documents/iOS_GDAL...) -t Use 16-bit Thumb instruction set (instead of 32-bit ARM) -a Architecture target for compilation (default: armv7) The target must be "device" or "simulator". Any additional arguments are passed to configure. The following environment variables affect the build process: GCC_VERSION (default: $default_gcc_version) IPHONEOS_DEPLOYMENT_TARGET (default: $default_iphoneos_version) MACOSX_DEPLOYMENT_TARGET (default: $default_macos_version) DEFAULT_PREFIX (default: $default_prefix) EOF } prefix="${DEFAULT_PREFIX}" echo Prefix: $prefix while getopts ":hp:a:t" opt; do case $opt in h ) usage ; exit 0 ;; p ) prefix="$OPTARG" ;; t ) thumb_opt=thumb ;; a ) DEFAULT_ARCHITECTURE="$OPTARG" ;; \? ) usage ; exit 2 ;; esac done shift $(( $OPTIND - 1 )) if (( $# &lt; 1 )); then usage exit 2 fi target=$1 shift case $target in device ) arch="${DEFAULT_ARCHITECTURE}" platform=iPhoneOS extra_cflags="-m${thumb_opt:-no-thumb} -mthumb-interwork" ;; simulator ) arch=i386 platform=iPhoneSimulator extra_cflags="-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.*}0000" ;; * ) echo No target found!!! usage exit 2 esac platform_dir="/Applications/Xcode.app/Contents/Developer/Platforms/${platform}.platform/Developer" platform_bin_dir="${platform_dir}/usr/llvm-gcc-${GCC_VERSION}/bin" platform_sdk_dir="${platform_dir}/SDKs/${platform}${IPHONEOS_DEPLOYMENT_TARGET}.sdk" prefix="${prefix}/${arch}/${platform}.platform/${platform}${IPHONEOS_DEPLOYMENT_TARGET}.sdk" echo library will be exported to $prefix export CC="${platform_bin_dir}/llvm-gcc-${GCC_VERSION}" export CFLAGS="-arch ${arch} -pipe -Os -gdwarf-2 -isysroot ${platform_sdk_dir} ${extra_cflags}" export LDFLAGS="-arch ${arch} -isysroot ${platform_sdk_dir}" export CXX="${platform_bin_dir}/llvm-g++-${GCC_VERSION}" export CXXFLAGS="${CFLAGS}" export CPP="${platform_bin_dir}/llvm-cpp-${GCC_VERSION}" export CXXCPP="${CPP}" ./configure \ --prefix="${prefix}" \ --host="${arch}-apple-darwin" \ --disable-shared \ --enable-static \ --with-unix-stdio-64=no \ "$@" || exit make install || exit cat &gt;&amp;2 &lt;&lt; EOF Build succeeded! Files were installed in $prefix EOF </code></pre> <p>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:</p> <ul> <li>default_gcc_version=4.2</li> <li>default_iphoneos_version=6.0</li> <li>default_macos_version=10.8</li> <li>default_architecture=armv7</li> <li>default_prefix="${HOME}/Documents/GDALLibrary"</li> </ul> <h2>And now building for multiple architectures</h2> <p>Using the preceding script (<code>build_gdal_ios.sh</code>) 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.</p> <p>The following script allows just that (save it to another name such as build_gdal_all_ios.sh):</p> <pre><code>#!/bin/bash make clean ./build_gdal_ios.sh -p ${HOME}/Documents/GDALLibrary -a armv7 device make clean ./build_gdal_ios.sh -p ${HOME}/Documents/GDALLibrary -a armv7s device make clean ./build_gdal_ios.sh -p ${HOME}/Documents/GDALLibrary simulator </code></pre> <p>After running this script you will have your libraries saved in your ${HOME}/Documents/GDALLibrary directory in subfolders:</p> <ul> <li>${HOME}/Documents/GDALLibrary/i386/iPhoneSimulator.platform/iPhoneSimulator6.0.sdk/lib</li> <li>${HOME}/Documents/GDALLibrary/armv7/iPhoneOS.platform/iPhoneSimulator6.0.sdk/lib</li> <li>${HOME}/Documents/GDALLibrary/armv7s/iPhoneOS.platform/iPhoneSimulator6.0.sdk/lib</li> </ul> <p>You can now use the executable lipo (for liposuction) to join the 3 libraries into a single one like so:</p> <pre><code>lipo ${HOME}/Documents/GDALLibrary/i386/iPhoneSimulator.platform/iPhoneSimulator6.0.sdk/lib/libgdal.a ${HOME}/Documents/GDALLibrary/armv7/iPhoneOS.platform/iPhoneSimulator6.0.sdk/lib/libgdal.a ${HOME}/Documents/GDALLibrary/armv7s/iPhoneOS.platform/iPhoneSimulator6.0.sdk/lib/libgdal.a -output ${HOME}/Documents/GDALLibrary/libgdal.a -create </code></pre> <p>... And you're done...</p> <h1>Add the static library to your XCode project</h1> <p>This step is rather straightforward:</p> <ol> <li>Create a new project in Xcode (4.5) or open the one you want to add GDAL to</li> <li>In the file explorer right click and select "Add files to projects"</li> <li>Select the libgdal.a created above along with the include files in one of the include directories (the 3 directories contain the same files)</li> <li>Add the following libraries to your XCode project (from the project framework list): <ul> <li>libstdc++.6.0.9.dylib</li> <li>libz.dylib</li> <li>libiconv.dylib</li> <li>libsqlite3.dylib</li> <li>libxml2.dylib (if Undefined symbols for architecture armv7: "_xmlCatalogResolveSystem" etc)</li> </ul></li> </ol> <p>Build your code. All should compile without trouble.</p> <h1>Start coding</h1> <p>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.</p> <p>Here you have two solutions:</p> <ol> <li>Write all your GDAL code inside .mm files which Xcode will then recognize as Objective-C++ files and will compile</li> <li>Use a class extension in your Objective-C files as described by Phil Jordan on his excellent article <a href="http://www.philjordan.eu/article/mixing-objective-c-c++-and-objective-c++" rel="nofollow">Mixing Objective-C++ and C++</a></li> </ol> <p>At one point I will be posting some GDAL code samples... but later...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload