How to Build Glib for iOS

How to build GLib for iOS

Given that you have built libffi and proxy-libintl for iOS, and installed both those to the same PREFIX as this script uses, this will build GLib for you:

#! /bin/bash

export MINVER="5.1" # the minimum supported OS version
export SDKVER="5.1" # SDK version
export PREFIX="$HOME/built-for-ios" # where the library goes

export DEVROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer"
export SDKROOT="${DEVROOT}/SDKs/iPhoneOS${SDKVER}.sdk"
export PKG_CONFIG_LIBDIR="${PREFIX}/lib/pkgconfig:${SDKROOT}/usr/lib/pkgconfig"
export COMMON_FLAGS="-arch armv7 -isysroot ${SDKROOT}"
export CPPFLAGS="-I${PREFIX}/include ${COMMON_FLAGS} -miphoneos-version-min=${MINVER}"
export CFLAGS="${CPPFLAGS}"
export LDFLAGS="-L${PREFIX}/lib ${COMMON_FLAGS} -Wl,-iphoneos_version_min,${MINVER}"
export CC="${DEVROOT}/usr/bin/gcc"
export CXX="${DEVROOT}/usr/bin/g++"
export OBJC="${CC}"
export LD="${CC}"

[ ! -d "${PREFIX}" ] && mkdir -p "${PREFIX}"
./configure --prefix="${PREFIX}" \
--build="x86_64-apple-darwin" \
--host="arm-apple-darwin" \
--enable-static \
--disable-shared \
glib_cv_stack_grows=no \
glib_cv_uscore=no \
ac_cv_func_posix_getgrgid_r=yes \
ac_cv_func_posix_getpwuid_r=yes

How to use glib on iphone?

While it's certainly possible to compile and link glib for iOS, it seems that there's a legal problem: glib uses LGPL and some think LGPL is not compatible with Apple's terms.

GLib usage with XCode

see Setting C++ compile flags in xcode

in short:

add result of
pkg-config --cflags --libs glib-2.0
to Build Settings -> Linking -> Other Linker Flags
NOT Build Settings -> Custom Compiler Flags -> Other C Flags

for some reason using
'pkg-config --cflags --libs glib-2.0' directly does not work yielding:

clang: error: no such file or directory: 'pkg-config --cflags --libs glib-2.0'


Related Topics



Leave a reply



Submit