为iPhone编译FreeType?

10
我在Windows、Linux和OSX上使用FreeType没有遇到任何问题,现在我想将我的技术移植到IOS上......但我找不到为其编译FreeType的方法。
起初我尝试将所有FT文件放入我的项目中,但显然这行不通。
然后我尝试按照这个教程创建一个静态库。虽然我无法测试它是否适用于arm目标,但对于模拟器目标则不行。
当我尝试将构建的库链接到XCode时,它会显示“libfreetype-simulator.a,文件是为未被链接的架构(i386)而构建的归档文件”,这很正常,因为命令“lipo -info libfreetype-simulator.a”告诉我该文件是为x86_64构建的。我尝试使用“./configure --i386-apple-darwin”进行配置,这里是日志。但最终生成的架构仍然是x86_64。
我真的一点头绪都没有,如何在世界上为i386、iPhone模拟器构建freetype呢?

请查看我在这个类似问题的答案这里:https://dev59.com/gU3Sa4cB1Zd3GeqPvoCn#11856736 - Zoodle Von Noodleson
7个回答

14

我使用了cxa答案中的链接,但它非常过时,并且我的配置行不适合在评论中。对于armv7,在使用6.1 SDK编译、最低版本为5.1且不需要bzip2的情况下,您需要这样做:

./configure '--without-bzip2' '--prefix=/usr/local/iphone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' 'CFLAGS=-arch armv7 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=5.1 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/ -miphoneos-version-min=5.1'
请注意缺少 -mdynamic-no-pic,如果保留此选项将会产生连接器警告和苹果公司的警告电子邮件。 同时请注意各种路径名已更改。

在这个链接中,+1 for the -mdynamic-no-pic部分可能会有问题。 - Adrian Lis
2
已经多年没有登录 Stack Overflow 了,我已经更新了正确的答案,谢谢! - Tom89

12

今天我在尝试为iOS编译FreeType时,偶然发现了这个项目:https://github.com/cdave1/freetype2-ios

只需下载、在xcode中打开并编译即可。 :)

希望这能对其他尝试在iOS上编译的人有所帮助。


5

针对Xcode 5,gcc已经更改了位置,因此配置应该是:

./configure --without-zlib --without-png --without-bzip2 '--prefix=/usr/local/iPhone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' 'CFLAGS=-arch armv7 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=6.1 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/ -miphoneos-version-min=6.1'

CC的位置可以通过运行以下命令找到:
$ xcrun -find -sdk iphoneos clang

4

也许有人会发现这很有用。
SDK 8.1,XCode 6.1
i386、x86_64、arm64(用于分析),armv7、armv7s

./configure CFLAGS="-arch i386"
make clean
make
cp objs/.libs/libfreetype.a libfreetype-i386.a

./configure CFLAGS="-arch x86_64"
make clean
make
cp objs/.libs/libfreetype.a libfreetype-x86_64.a

./configure --without-zlib --without-png --without-bzip2 '--prefix=/usr/local/iPhone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' 'CFLAGS=-arch armv7 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=7.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/ -miphoneos-version-min=7.0'
make clean
make
cp objs/.libs/libfreetype.a libfreetype-armv7.a

./configure --without-zlib --without-png --without-bzip2 '--prefix=/usr/local/iPhone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' 'CFLAGS=-arch arm64 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=7.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/ -miphoneos-version-min=7.0'
make clean
make
cp objs/.libs/libfreetype.a libfreetype-arm64.a

./configure --without-zlib --without-png --without-bzip2 '--prefix=/usr/local/iPhone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' 'CFLAGS=-arch armv7s -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=7.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/ -miphoneos-version-min=7.0'
make clean
make
cp objs/.libs/libfreetype.a libfreetype-armv7s.a

lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-armv7.a libfreetype-armv7s.a libfreetype-arm64.a 

4

对于在 Xcode 6.1 上最小目标为 7.1 的 iOS SDK 8.1,以下方法有效:

./configure --without-zlib --without-png --without-bzip2 '--prefix=/usr/local/iPhone' '--host=arm-apple-darwin' '--enable-static=yes' '--enable-shared=no' 'CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' 'CFLAGS=-arch armv7 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=7.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/usr/include/libxml2/ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/' 'AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar' 'LDFLAGS=-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk/ -miphoneos-version-min=7.0'

非常感谢!这节省了我大量的时间! - liuyaodong

2
这个 shell 脚本适用于 x86_64 平台,你可能需要看一下。
我使用它来编译 freetype2.5.5,并得到了 armv7、arm64、i386 和 x86_64 的结果。当然,它也将它们合并成一个静态库。

谢谢!你的答案似乎是截至2015年9月仍然有效的唯一解决方案。 - Pascal T.

0

为了让 FreeType 平稳编译,重要的是将变量“CC”、“CFLAGS”、“LDFLAGS”和“AR”作为参数传递给configure不是环境变量。

在某个时刻,configure会运行本地机器的gcc,如果您有指向iPhone SDK的“LDFLAGS”,它将导致编译失败。 将变量传递给configure似乎可以解决此问题。


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