如何在iOS上构建GLib

5
我希望您能在我的iOS应用中使用lasem,但是编译lasem需要glib。如何构建它?
我从https://git.gnome.org/browse/glib/refs/tags下载了glib-2.37.4。我使用autogen.sh获取了一个configure文件,运行了make并在Mac上进行了安装。我编写了一个Shell脚本来构建iOS的glib,如下所示:
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

当我运行这个脚本时,会返回以下结果:
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

我能做些什么?


请不要...认真的... - Macmade
1
顺便提一下,GLib是在LGPL许可下发布的,由于静态链接,在iOS上存在许多问题,并且通常在法律上不兼容... - Macmade
1
GCC - 这个脚本正在寻找编译器而不是Clang - 顺便提一下,GCC已经被苹果公司宣布为MacOSX和iOS的编译器,至少在他们的开发工具中不再得到支持或更新。除非您依赖于MacPorts或类似工具来获取它,否则它将在下一个版本中消失。 - marko
4
这并不完全不兼容,只是有点复杂。 LGPL 的“精神”是最终用户应该能够修改 LGPL 源代码,并因此改进/更改产品。在动态链接时,只需替换动态库即可轻松实现此目的,但使用静态链接时,您需要提供使用的LGPL源代码、专有的目标文件以及编译和重新链接这些文件的方法,以便仍然可以修改生成的产品。 - Havard Graff
即使进行静态链接也不行,因为用户必须自己上传应用商店,这会侵犯版权和应用商店的法律。LGPL是为过去的不同世界而制定的。 - Lothar
1个回答

8

如果您已经为iOS构建了libffiproxy-libintl,并将它们安装到与此脚本使用的相同PREFIX目录下,那么这将为您构建GLib:

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

谢谢。我成功地使用您的脚本制作了libffi和gettext,在我的~/built-for-ios/lib目录下有libintl.a libintl.la gettext libgettextpo.a... 但是当我配置glib时仍然显示:checking for ngettext in -lintl... no configure: error: ***你必须在C库中拥有gettext支持,或者使用GNU gettext库。(http://www.gnu.org/software/gettext/gettext.html) - Tinyfool
在config.log中,我可以看到“configure: 8750: 检查-lintl中ngettext的情况”,... 架构armv7的未定义符号: "_CFArrayGetCount",引用自: libintl.a(langprefs.o)中的__nl_language_preferences_default ld:找不到架构armv7的符号(s) collect2:ld返回1个退出状态 - Tinyfool
是的,因此引用了libintl-proxy。建立它,它将充当一个虚拟(代理)实现。 - Havard Graff
在glib的配置阶段,我遇到了意外的configure: error: *** No iconv() implementation found in C library or libiconv错误,这是否意味着我也需要交叉编译libiconv? - duhanebel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接