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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章