Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scripts for building Gdal into a static library for iOS, build-gdal-combined-lib.sh will build a single lib with armv7 armv7s arm64 and simulator slices
#!/bin/bash
PREFIX=`pwd`/install/
rm -rf $PREFIX
mkdir $PREFIX
LOG=./log
rm -rf $LOG
mkdir $LOG
if [ -e ${PREFIX} ]
then
echo removing ${PREFIX}
rm -rf ${PREFIX}
fi
mkdir ${PREFIX}
for f in "armv7" "armv7s" "arm64"; do
echo Building $f
./build_gdal_ios.sh -p ${PREFIX} -a $f device 2>&1 | tee "${LOG}/${f}.txt"
done
echo Building simulator
for f in "i386" "x86_64"; do
echo Building $f
./build_gdal_ios.sh -p ${PREFIX} -a $f simulator 2>&1 | tee "${LOG}/simulator.txt"
done
SDK_VERSION=8.3
lipo \
${PREFIX}/i386/iphonesimulator${SDK_VERSION}.sdk/lib/libgdal.a \
${PREFIX}/x86_64/iphonesimulator${SDK_VERSION}.sdk/lib/libgdal.a \
${PREFIX}/armv7/iphoneos${SDK_VERSION}.sdk/lib/libgdal.a \
${PREFIX}/armv7s/iphoneos${SDK_VERSION}.sdk/lib/libgdal.a \
${PREFIX}/arm64/iphoneos${SDK_VERSION}.sdk/lib/libgdal.a \
-output ${PREFIX}/libgdal.a \
-create | tee $LOG/lipo.txt
lipo \
${PREFIX}/i386/iphonesimulator${SDK_VERSION}.sdk/lib/libproj.a \
${PREFIX}/x86_64/iphonesimulator${SDK_VERSION}.sdk/lib/libproj.a \
${PREFIX}/armv7/iphoneos${SDK_VERSION}.sdk/lib/libproj.a \
${PREFIX}/armv7s/iphoneos${SDK_VERSION}.sdk/lib/libproj.a \
${PREFIX}/arm64/iphoneos${SDK_VERSION}.sdk/lib/libproj.a \
-output ${PREFIX}/libproj.a \
-create | tee $LOG/lipo-proj.txt
#create zipfile for cocoapods distribution
cd ${PREFIX}
mkdir GDAL
cp libgdal.a ${PREFIX}/libproj.a GDAL
cp arm64/iphoneos8.3.sdk/include/*.h GDAL
zip gdal.zip GDAL/*
#!/bin/bash
set -u
default_iphoneos_version=8.3
default_architecture=armv7
export IPHONEOS_DEPLOYMENT_TARGET="${IPHONEOS_DEPLOYMENT_TARGET:-$default_iphoneos_version}"
DEFAULT_ARCHITECTURE="${DEFAULT_ARCHITECTURE:-$default_architecture}"
DEFAULT_PREFIX="${HOME}/Desktop/iOS_GDAL"
usage ()
{
cat >&2 << EOF
Usage: ${0} [-h] [-p prefix] [-a arch] target [configure_args]
-h Print help message
-p Installation prefix (default: \$HOME/Documents/iOS_GDAL...)
-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:
IPHONEOS_DEPLOYMENT_TARGET (default: $default_iphoneos_version)
DEFAULT_PREFIX (default: $default_prefix)
EOF
}
prefix="${DEFAULT_PREFIX}"
while getopts ":hp:a:" opt; do
case $opt in
h ) usage ; exit 0 ;;
p ) prefix="$OPTARG" ;;
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=" "
;;
simulator )
arch="${DEFAULT_ARCHITECTURE}"
platform=iphonesimulator
extra_cflags="-D__IPHONE_OS_VERSION_MIN_REQUIRED=${IPHONEOS_DEPLOYMENT_TARGET%%.*}0000"
;;
* )
echo No target found!!!
usage
exit 2
esac
if [ $arch = "arm64" ]
then
host="arm-apple-darwin"
else
host="${arch}-apple-darwin"
fi
echo "building for host ${host}"
platform_dir=`xcrun -find -sdk ${platform} --show-sdk-platform-path`
platform_sdk_dir=`xcrun -find -sdk ${platform} --show-sdk-path`
prefix="${prefix}/${arch}/${platform}${IPHONEOS_DEPLOYMENT_TARGET}.sdk"
echo
echo library will be exported to $prefix
#setup compiler flags
export CC=`xcrun -find -sdk iphoneos gcc`
export CFLAGS="-Wno-error=implicit-function-declaration -arch ${arch} -pipe -Os -gdwarf-2 -isysroot ${platform_sdk_dir} ${extra_cflags}"
export LDFLAGS="-arch ${arch} -isysroot ${platform_sdk_dir}"
export CXX=`xcrun -find -sdk iphoneos g++`
export CXXFLAGS="${CFLAGS}"
export CPP=`xcrun -find -sdk iphoneos cpp`
export CXXCPP="${CPP}"
echo CFLAGS ${CFLAGS}
#set proj4 install destination
proj_prefix=$prefix
echo install proj to $proj_prefix
#download proj4 if necesary
if [ ! -e proj-4.8.0 ]
then
echo proj4 missing, downloading
wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
tar -xzf proj-4.8.0.tar.gz
fi
#configure and build proj4
pushd proj-4.8.0
echo
echo "cleaning proj"
make clean
echo
echo "configure proj"
./configure \
--prefix=${proj_prefix} \
--enable-shared=no \
--enable-static=yes \
--host=$host \
"$@" || exit
echo
echo "make install proj"
time make install || exit
popd
#download gdal if necesary
if [ ! -e gdal-1.11.2 ]
then
wget http://download.osgeo.org/gdal/1.11.0/gdal-1.11.2.tar.gz
tar -xzf gdal-1.11.2.tar.gz
fi
#configure and build gdal
cd gdal-1.11.2
echo "cleaning gdal"
make clean
echo
echo "configure gdal"
./configure \
--prefix="${prefix}" \
--host=$host \
--disable-shared \
--enable-static \
--with-hide-internal-symbols \
--with-unix-stdio-64=no \
--with-geos=no \
--without-pg \
--without-grass \
--without-libgrass \
--without-cfitsio \
--without-pcraster \
--without-netcdf \
--without-ogdi \
--without-fme \
--without-hdf4 \
--without-hdf5 \
--without-jasper \
--without-kakadu \
--without-grib \
--without-mysql \
--without-ingres \
--without-xerces \
--without-odbc \
--without-curl \
--without-idb \
--without-sde \
--with-sse=no \
--with-avx=no \
--with-static-proj4=${prefix} \
--with-sqlite3=${platform_sdk_dir} \
|| exit
#echo '#include "cpl_config_extras.h"' >> port/cpl_config.h
echo
echo "building gdal"
time make
echo
echo "installing"
time make install
echo "Gdal build complete"
@JesseCrocker

This comment has been minimized.

Copy link
Owner Author

JesseCrocker commented Jun 27, 2014

Note: the combined lib is 383mb, dont worry, it wont increase your app bundle by that much, probably only 10mb. It is also normal for it to take 45 minutes to build, thats why we have a static library for it.

@LZHHHTBNO

This comment has been minimized.

Copy link

LZHHHTBNO commented Aug 27, 2014

what command should be enter in the terminal?

@LZHHHTBNO

This comment has been minimized.

Copy link

LZHHHTBNO commented Aug 27, 2014

variable has incomplete type 'VSIStatBufL'
(aka 'stat64') how to fix it!

@LZHHHTBNO

This comment has been minimized.

Copy link

LZHHHTBNO commented Aug 27, 2014

when i build there is a error
Unsupported architecture
please help me thanks。

@johnklawlor

This comment has been minimized.

Copy link

johnklawlor commented Jun 8, 2015

@JesseCrocker why is it that the combined library is 380+ mb large (mine is actually 500+ mb all 5 combined), but it will only increase the app bundle by 10 mb? when i check the size of my app on my phone, it says 500mb!

@gunnarblom

This comment has been minimized.

Copy link

gunnarblom commented Mar 14, 2016

@JesseCrocker works perfectly, thanks! I'm trying to modify the script to include GEOS support, but I can't figure out how. Do you happen to know how to do that?

@shalomfriss

This comment has been minimized.

Copy link

shalomfriss commented Sep 25, 2017

getting this error?
Undefined symbols for architecture x86_64:
"_iconv", referenced from:
CPLRecodeIconv(char const*, char const*, char const*) in libgdal.a(cpl_recode_iconv.o)
CPLRecodeFromWCharIconv(wchar_t const*, char const*, char const*) in libgdal.a(cpl_recode_iconv.o)
"_iconv_close", referenced from:
CPLRecodeIconv(char const*, char const*, char const*) in libgdal.a(cpl_recode_iconv.o)
CPLRecodeFromWCharIconv(wchar_t const*, char const*, char const*) in libgdal.a(cpl_recode_iconv.o)
"_iconv_open", referenced from:
CPLRecodeIconv(char const*, char const*, char const*) in libgdal.a(cpl_recode_iconv.o)
CPLRecodeFromWCharIconv(wchar_t const*, char const*, char const*) in libgdal.a(cpl_recode_iconv.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [gdalinfo] Error 1
make: *** [apps-target] Error 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.