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

基调:这是一篇水文,技术含量不大,主要是留给以后的自己回顾用的。但提到的某些编译错误的解决过程有一定代表性,难保谁搜索到这篇文章不能从中找到解决自己手中问题的方法,如果不小心帮到了谁,也算无心的好事吧。虽然都是些小问题,搜搜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的目录变化应该是脚本需要调整的主要提防,需要单独确认。


freetype2.4.6在iOS上各版本的编译脚本_第1张图片

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


下面开始。


==> iOS7

make clean
./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"
make clean;make
cp objs/.libs/libfreetype.a libfreetype-i386.a

make clean
./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"
make clean;make
cp objs/.libs/libfreetype.a libfreetype-x86_64.a

make clean
./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"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-arm7.a

make clean
./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"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-arm7s.a

make clean
./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"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-arm64.a


lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-arm7.a libfreetype-arm7s.a libfreetype-arm64.a
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

make clean
./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"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-i386.a

make clean
./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"
make clean;make
cp objs/.libs/libfreetype.a libfreetype-x86_64.a

make clean
./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"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-arm7.a

make clean
./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"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-arm7s.a

lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-arm7.a libfreetype-arm7s.a 
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

make clean
./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"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-i386.a

make clean
./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"
make clean;make
cp objs/.libs/libfreetype.a libfreetype-x86_64.a

make clean
./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"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-arm6.a

make clean
./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"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-arm7.a

lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-arm6.a libfreetype-arm7.a
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

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

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

make clean
./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"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-arm6.a

make clean
./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"
make clean; make
cp objs/.libs/libfreetype.a libfreetype-arm7.a

lipo -create -output libfreetype.a libfreetype-i386.a libfreetype-x86_64.a libfreetype-arm6.a libfreetype-arm7.a
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





你可能感兴趣的:(freetype2.4.6在iOS上各版本的编译脚本)