freetype2.4.6在iOS上各版本的编译脚本


http://blog.csdn.net/madongchunqiu/article/details/12402257


基调:这是一篇水文,技术含量不大,主要是留给以后的自己回顾用的。但提到的某些编译错误的解决过程有一定代表性,难保谁搜索到这篇文章不能从中找到解决自己手中问题的方法,如果不小心帮到了谁,也算无心的好事吧。虽然都是些小问题,搜搜stackoverflow基本也能搞定,不过能省一分钟总是好的吧,更何况还是中文呢。

申明:关于这篇文章的留言或来信,作者绝大多数可能性不会回复,请勿怪。


关于版本:freetype2.4.6只是作者一直在使用的版本,没有特别的指代意义。因为作者对freetype做了一些定制,所以在还能使用的前提下,就没有升级到更高的版本了。所以在iOS的更迭中,需要自己搞定编译。

关于系统和编译环境:编译环境为macOSX,编译器是Xcode。因为苹果对Xcode和SDK的升级基本和iOS的步调一致,以下仅列出iOS版本,其它环境均采用适合那个版本的macOSX和Xcode(含对应的SDK以及Command Line Tools)来进行编译的。


版本升级中需要检查的一些注意事项:

1. 从某版本开始,xcode和command line tools就分开了。下载了xcode后,还需要单独下载并安装command line tools;

2. 由于设备采用的芯片升级,armv6, armv7, armv7s以及arm64代表了各个不同时期的设备,为了支持不同的设备,可能需要编译新的target版本;

3. 版本升级中,xcode、command line tools、SDK的目录变化应该是脚本需要调整的主要提防,需要单独确认。



【凉爽的秋天到了,附上win7自带图片一张】


下面开始。


==> iOS7

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. make clean  
  2. ./configure --prefix=/usr/local/iphone --enable-static=yes --enable-shared=no CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc CFLAGS="-arch i386 -Wno-extended-offsetof -miphoneos-version-min=4.2 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk" CPP=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar LDFLAGS="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -miphoneos-version-min=4.2"  
  3. make clean;make  
  4. cp objs/.libs/libfreetype.a libfreetype-i386.a  
  5.   
  6. make clean  
  7. ./configure --prefix=/usr/local/iphone --enable-static=yes --enable-shared=no CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc CFLAGS="-arch x86_64  -Wno-extended-offsetof -miphoneos-version-min=4.2 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk" CPP=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar LDFLAGS="-arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -miphoneos-version-min=4.2"  
  8. make clean;make  
  9. cp objs/.libs/libfreetype.a libfreetype-x86_64.a  
  10.   
  11. make clean  
  12. ./configure --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/cc  CFLAGS="-arch armv7 -pipe -std=c99 -Wno-extended-offsetof -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=4.2 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk" AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar LDFLAGS="-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -miphoneos-version-min=4.2"  
  13. make clean; make  
  14. cp objs/.libs/libfreetype.a libfreetype-arm7.a  
  15.   
  16. make clean  
  17. ./configure --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/cc  CFLAGS="-arch armv7s -pipe -std=c99 -Wno-extended-offsetof -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=5.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk" AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar LDFLAGS="-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -miphoneos-version-min=4.2"  
  18. make clean; make  
  19. cp objs/.libs/libfreetype.a libfreetype-arm7s.a  
  20.   
  21. make clean  
  22. ./configure --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/cc  CFLAGS="-arch arm64 -pipe -std=c99 -Wno-extended-offsetof -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=6.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk" AR=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar LDFLAGS="-arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -miphoneos-version-min=6.0"  
  23. make clean; make  
  24. cp objs/.libs/libfreetype.a libfreetype-arm64.a  
  25.   
  26.   
  27. lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-arm7.a libfreetype-arm7s.a libfreetype-arm64.a  
  28. lipo -info libfreetype.a   

关于iOS7的说明:

1. 第一个改变是增加了arm64的target。不清楚是不是必选。

2. 第二个改变是command line tools的位置变成了:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin (注:好像早就变了,不过我上个版本的那些编译工具没有换位置也行,而这个版本在老地方就找不到clang/ar之类的工具了)

3. 增加了i386选项的CFLAGS和LDFLAGS的编译和链接选项。不加入的话会有些奇怪的bug,下面会详述。


关于升级iOS7后遇到的各种问题:

1. 编译i386时,增加-Wno-extended-offsetof的编译选项,是因为编译中会出现编译警告:warning: using extended field designator is an extension [-Wextended-offsetof]

2. 编译i386时,增加-miphoneos-version-min=4.2的编译选项,因为编译出错,在config.log中有如下提示:building for MacOSX, but linking against dylib built for iOS Simulator file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk/usr/lib/libSystem.dylib' for architecture i386

3. 编译i386时,若删除编译链接选项中的SDK目录,可以编译通过,但是在运行时会出现调用错误:Detected an attempt to call a symbol in system libraries that is not present on the iPhone: open$UNIX2003 xxx。 网上说这是一个在4.1左右出现的bug,后来修复了。这个bug是在调试编译中偶然发现的问题,当时估计是参考了上个版本一直没派上用场的x86_64的编译命令,把编译连接选项中的SDK目录删掉了做测试,结果链接到了某个不确定的SDK中吧?或许是我的环境设置中的某些目录起了怪作用。所以我一贯还是推崇在脚本中将目录写清楚的,至少要单独一行写明可能会涉及到的目录。如果过于依赖系统设定的目录,则在不同的机器上可能会有些意料不到的问题,一时想不到点子上的话,则会很伤很伤人。也算是个教训吧。

4. 这次升级主要是修改了i386的选项和增加arm64。别的都没有问题。i386修改较多,可以比照下面的iOS6版本。


==> iOS6

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. make clean  
  2. ./configure --prefix=/usr/local/iphone --enable-static=yes --enable-shared=no CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc CFLAGS="-arch i386 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk" CPP=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/cpp AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar LDFLAGS="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk"  
  3. make clean; make  
  4. cp objs/.libs/libfreetype.a libfreetype-i386.a  
  5.   
  6. make clean  
  7. ./configure --prefix=/usr/local/iphone --enable-static=yes --enable-shared=no CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc CFLAGS="-arch x86_64" CPP=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/cpp AR=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar LDFLAGS="-arch x86_64"  
  8. make clean;make  
  9. cp objs/.libs/libfreetype.a libfreetype-x86_64.a  
  10.   
  11. make clean  
  12. ./configure --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=4.2 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/include -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=4.2"  
  13. make clean; make  
  14. cp objs/.libs/libfreetype.a libfreetype-arm7.a  
  15.   
  16. make clean  
  17. ./configure --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 armv7s -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=5.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/usr/include -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 armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -miphoneos-version-min=4.2"  
  18. make clean; make  
  19. cp objs/.libs/libfreetype.a libfreetype-arm7s.a  
  20.   
  21. lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-arm7.a libfreetype-arm7s.a   
  22. lipo -info libfreetype.a   


关于iOS6的说明:

1. 增加了armv7s的target。


关于升级iOS6后遇到的各种问题:

1. 编译armv7时,编译出错,在config.log中有如下错误:ld: library not found for -lcrt1.3.1.o。 结果问题是SDK的版本号忘了修改了,都6.x了,还写着5.x。所以版本升级时,确认各编译链接目录的正确性是很有必要的。


==> iOS5

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. make clean  
  2. ./configure --prefix=/usr/local/iphone --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc CFLAGS="-arch i386 -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/usr/include -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk" CPP=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar LDFLAGS="-arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk"  
  3. make clean; make  
  4. cp objs/.libs/libfreetype.a libfreetype-i386.a  
  5.   
  6. make clean  
  7. ./configure --prefix=/usr/local/iphone --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc CFLAGS="-arch x86_64" CPP=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ar LDFLAGS="-arch x86_64"  
  8. make clean;make  
  9. cp objs/.libs/libfreetype.a libfreetype-x86_64.a  
  10.   
  11. make clean  
  12. ./configure --prefix=/usr/local/iphone --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc CFLAGS="-arch armv6 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=5.0 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk" AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar LDFLAGS="-arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -miphoneos-version-min=5.0"  
  13. make clean; make  
  14. cp objs/.libs/libfreetype.a libfreetype-arm6.a  
  15.   
  16. make clean  
  17. ./configure --prefix=/usr/local/iphone --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/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.0 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk" AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar LDFLAGS="-arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -miphoneos-version-min=5.0"  
  18. make clean; make  
  19. cp objs/.libs/libfreetype.a libfreetype-arm7.a  
  20.   
  21. lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-arm6.a libfreetype-arm7.a  
  22. lipo -info libfreetype.a  


关于升级iOS5后遇到的各种问题:

1. 在编译armv6和armv7时,删除编译选项-mdynamic-no-pic,因为有如下错误:ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _FT_Stream_Open from freetype2/libfreetype.a(ftsystem.o). To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie 


==> iOS4.3

[plain]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. make clean  
  2. ./configure CFLAGS="-arch i386"  
  3. make  
  4. cp objs/.libs/libfreetype.a libfreetype-i386.a  
  5.   
  6. make clean  
  7. ./configure CFLAGS="-arch x86_64"  
  8. make clean;make  
  9. cp objs/.libs/libfreetype.a libfreetype-x86_64.a  
  10.   
  11. make clean  
  12. ./configure --prefix=/usr/local/iphone --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2  CFLAGS="-arch armv6 -pipe -mdynamic-no-pic -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=4.3 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/include/libxml2 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar LDFLAGS="-arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk -miphoneos-version-min=4.3"  
  13. make clean; make  
  14. cp objs/.libs/libfreetype.a libfreetype-arm6.a  
  15.   
  16. make clean  
  17. ./configure --prefix=/usr/local/iphone --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2  CFLAGS="-arch armv7 -pipe -mdynamic-no-pic -std=c99 -Wno-trigraphs -fpascal-strings -O2 -Wreturn-type -Wunused-variable -fmessage-length=0 -fvisibility=hidden -miphoneos-version-min=4.3 -I/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/include/libxml2 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk" CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar LDFLAGS="-arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk -miphoneos-version-min=4.3"  
  18. make clean; make  
  19. cp objs/.libs/libfreetype.a libfreetype-arm7.a  
  20.   
  21. lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-arm6.a libfreetype-arm7.a  
  22. lipo -info libfreetype.a  

关于编译iOS4.3时遇到的各种问题:

1. 运行时报错:Detected an attempt to call a symbol in system libraries that is not present on the iPhone: open$UNIX2003。解决方法是重装Xcode?或是升级Xcode4.1到 Xcode4.2



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值