How to build GLib for iOS
Asked Answered
S

1

5

I want to use lasem in my iOS App, but compiling lasem needs glib. How to build it?

I download glib-2.37.4 from https://git.gnome.org/browse/glib/refs/tags. I then used autogen.sh to get a configure file, ran make and installed on mac. I wrote a shell script try to build glib for iOS, as blow:

export path=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/:$path
 export CC=arm-apple-darwin10-llvm-gcc-4.2
 export CFLAGS="-arch armv7"
 export LDFLAGS="-miphoneos-version-min=2.0"
 export LD="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld--disable-cxx"
./configure --prefix=/usr/local/ios/ --host=arm-apple-darwin10 --enable-static=yes --enable-shared=no CC=$CC CFLAGS=$CFLAGS CPP=cpp AR=ar LDFLAGS=$LDFLAGS LD=$LD

When I run this script, return as:

checking for arm-apple-darwin10-gcc... arm-apple-darwin10-llvm-gcc-4.2
checking whether the C compiler works... no
configure: error: in `/Users/tinyfool/Downloads/glib-2.34.3':
configure: error: C compiler cannot create executables

What can I do?

Sorcerer answered 14/7, 2013 at 10:33 Comment(5)
Don't... Seriously...Sleeve
And by the way, GLib is released under the LGPL license, which have a lot of issues with iOS, due to static linking, and is usually incompatible legally...Sleeve
GCC - which this script is finding instead of Clang as a compiler - is incidentally deprecated as a compiler for both MacOSX and iOS - at least to the extent that Apple is no longer supporting or updating a release with their dev-tools. It will be going away with the next release unless you rely on MacPorts or similar to obtain it.Beutler
It is not at all incompatible, it is just a bit complicated. The "spirit" of LGPL is that the end-user should be able to modify the LGPL source-code and improve/change the product as a result. When dynamically linking, this is as easy as replacing the dynamic libraries, but with static linking you need to provide LGPL-source used, proprietary object-files, and a way to compile and relink these, so that modifying the resulting product is still possible.Rodrigo
Even with static relinking it is not possible as the user has to upload it to the app store themself breaking copyright and app store laws. LGPL was made for a different world of the past.Cressler
R
8

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
Rodrigo answered 18/7, 2013 at 20:32 Comment(4)
Thanks. I use your script success make libffi and gettext, at my ~/built-for-ios/lib has libintl.a libintl.la get text libgettextpo.a ... But when I configure glib still said that: checking for ngettext in -lintl... no configure: error: *** You must have either have gettext support in your C library, or use the *** GNU gettext library. (gnu.org/software/gettext/gettext.htmlSorcerer
At config.log I can see "configure:8750: checking for ngettext in -lintl",... Undefined symbols for architecture armv7: "_CFArrayGetCount", referenced from: __nl_language_preferences_default in libintl.a(langprefs.o) ld: symbol(s) not found for architecture armv7 collect2: ld returned 1 exit statusSorcerer
yes, hence the reference to the libintl-proxy. Build that instead, and it will act as a dummy(proxy)-implementation.Rodrigo
During the configure phase of glib I get an unexpected configure: error: *** No iconv() implementation found in C library or libiconv does it mean I need to x-compile libiconv as well?Stamps

© 2022 - 2024 — McMap. All rights reserved.