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 -h, .
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... ...