Including GDAL / OGR in an iOS Project - Quick Start Guide

Here's the problem: GDAL is a fantastic open source library for managing complex GIS data, both raster and vector. It is fully compiled for Mac OS (kindly provided by William Kingsbury) and other platforms, but not for iOS.

Looking through the network, you can find fragments of (relatively old) information on the topic of creating the iOS library, starting with the famous script from pseudogreen , which was written more than 3 years ago. There are also bits and pieces on the stack overflow, such as GDAL / OGR on the iPhone , which provide additional information.

This article is intended to cover all the steps that I took, which led me to fully functional integration of GDAL / OGR in a simple iOS application using iOS6 and XCode 4.5.5

+5
source share
1 answer

Note

This answer was written some time ago, and a longer one works with Xcode 6 and above. Please check this link for a more accurate answer to this problem.

Introduction

Including GDAL in your iOS app is a five-step process:

  • Download the GDAL source code from the GDAL website.
  • Run the configuration / build / install script below
  • Add the resulting static library to your iOS project along with the included files
  • Link to additional libraries in the iOS project
  • ... GDAL OGR .

GDAL

GDAL - ++, - www.gdal.org. ​​ 1.9.0. , .

script GDAL iOS

GDAL iOS, (.a). , iOS6, :

  • i386
  • armv7 iPhone 3GS iPhone 4S
  • armv7s iPhone 5

script 1

script, pseudogreen, .

.sh: build_gdal_ios.sh.

, script , gdal, :

  • :

    `sh build_gdal_ios.sh -p "location where you want to save the resulting files" simulator`
    
  • :

    `sh build_gdal_ios.sh -p "location where you want to save the resulting files" -a "architecture" device`
    

sh build_gdal_ios.sh -h, .

    #!/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 >&2 << 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 (( $# < 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 >&2 << EOF

    Build succeeded!  Files were installed in

      $prefix


   EOF

, script , , SDK LLVM Apple:

  • default_gcc_version = 4.2
  • default_iphoneos_version = 6,0
  • default_macos_version = 10,8
  • default_architecture = ARMv7
  • default_prefix = "$ {HOME}//GDALLibrary"

script (build_gdal_ios.sh), ... 3, .

script ( , build_gdal_all_ios.sh):

#!/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

script ${HOME}/Documents/GDALLibrary :

  • ${HOME}/Documents/GDALLibrary/i386/iPhoneSimulator.platform/iPhoneSimulator6.0.sdk/lib
  • ${HOME}/Documents/GDALLibrary/armv7/iPhoneOS.platform/iPhoneSimulator6.0.sdk/lib
  • ${HOME}/Documents/GDALLibrary/armv7s/iPhoneOS.platform/iPhoneSimulator6.0.sdk/lib

( ), 3 :

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

... ...

XCode

:

  • Xcode (4.5) , GDAL,
  • " "
  • libgdal.a include (3 )
  • XCode ( ):
    • libstd++. 6.0.9.dylib
    • libz.dylib
    • libiconv.dylib
    • libsqlite3.dylib
    • libxml2.dylib( Undefined armv7: "_xmlCatalogResolveSystem" ..)

. .

: ++ ( ) Objective-C. GDAL .m, XCode ++.

:

- GDAL... ...

+16

All Articles