ios/android交叉編譯引數設定
阿新 • • 發佈:2019-01-09
很多開源庫的build方式都是configure->make模式,要做交叉編譯關鍵就在於給configuare傳遞正確的引數,包括指定c/c++編譯器、前處理器及編譯標誌,這些引數會影響到動態生成的標頭檔案,以便產生正確的目標架構基礎資料型別定義等。在做手機平臺程式時,移植用到的第三方庫是個很必須且繁瑣的工作,現在把用於ios和android的配置命令總結一下以備忘。
iOS:裝了xcode4之後會發現命令列上的gcc居然沒有,其實它被封裝在xcrun gcc命令裡了,所以配置引數為:
./configure --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC='xcrun -sdk iphoneos gcc -std=c99' CFLAGS='-arch armv6 -O2 -miphoneos-version-min=4.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/include/libxml2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk' CXX="xcrun -sdk iphoneos g++" CXXFLAGS='-arch armv6 -O2 -miphoneos-version-min=4.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/include/libxml2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk' CPP='xcrun -sdk iphoneos cpp' AR='xcrun -sdk iphoneos ar' LDFLAGS='-arch armv6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk -miphoneos-version-min=4.0'
android:安卓上stl不是做為個系統內建標準庫,而像是個第三方庫一樣提供,如果是編譯c++程式,要記得單獨為它指定位置。另外,我編android程式的時候,習慣是重寫CC、CXX這些環境變數並匯出,然後簡單的調configuare,免得帶一堆長長的引數:
#!/usr/bin/bash
export SYSROOT="H:/andk/platforms/android-9/arch-arm"
export CC="$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-gcc.exe --sysroot=$SYSROOT"
export CXX="$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-g++.exe --sysroot=$SYSROOT -Ih:/andk/sources/cxx-stl/gnu-libstdc++/include"
export AR="$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-ar.exe --sysroot=$SYSROOT"
每次要交叉編譯時,先source一下上面這個指令碼,之後就直接./configure –host=arm-eabi了。
另外提一下,為什麼iOS的CFLAGS要指定-arch=armv6而android不用?因為android的用於各個架構的編譯器是分離的,放在各自的目錄中,如toolchains/arm-linux-androideabi-4.4.3就是專用於arm的,其它x86、mips等都有對應的一套。而iOS的xcrun gcc實際上支援真機arm和模擬器x86兩種,所以它需要額外指定目標架構。
========================================
另外,luajit的編譯比較特殊,它沒有configuare,全是在makefile裡搞定配置。
所以編iOS時的命令為:
ISDK=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
ISDKVER=iPhoneOS5.1.sdk
ISDKP=$ISDK/usr/bin/
ISDKF="-arch armv6 -isysroot $ISDK/SDKs/$ISDKVER"
make HOST_CC="gcc -m32 -arch i386" CROSS=$ISDKP TARGET_FLAGS="$ISDKF" TARGET_SYS=iOS TARGET=arm
編android時:
make CROSS=/cygdrive/h/andk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi- TARGET_FLAGS=--sysroot=H:/andk/platforms/android-9/arch-arm TARGET_SYS=Linux TARGET=ARM
iOS:裝了xcode4之後會發現命令列上的gcc居然沒有,其實它被封裝在xcrun gcc命令裡了,所以配置引數為:
./configure --host=arm-apple-darwin --enable-static=yes --enable-shared=no CC='xcrun -sdk iphoneos gcc -std=c99' CFLAGS='-arch armv6 -O2 -miphoneos-version-min=4.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/include/libxml2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk' CXX="xcrun -sdk iphoneos g++" CXXFLAGS='-arch armv6 -O2 -miphoneos-version-min=4.0 -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/include/libxml2 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk' CPP='xcrun -sdk iphoneos cpp' AR='xcrun -sdk iphoneos ar' LDFLAGS='-arch armv6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk -miphoneos-version-min=4.0'
android:安卓上stl不是做為個系統內建標準庫,而像是個第三方庫一樣提供,如果是編譯c++程式,要記得單獨為它指定位置。另外,我編android程式的時候,習慣是重寫CC、CXX這些環境變數並匯出,然後簡單的調configuare,免得帶一堆長長的引數:
#!/usr/bin/bash
export SYSROOT="H:/andk/platforms/android-9/arch-arm"
export CC="$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-gcc.exe --sysroot=$SYSROOT"
export CXX="$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-g++.exe --sysroot=$SYSROOT -Ih:/andk/sources/cxx-stl/gnu-libstdc++/include"
export AR="$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-ar.exe --sysroot=$SYSROOT"
每次要交叉編譯時,先source一下上面這個指令碼,之後就直接./configure –host=arm-eabi了。
另外提一下,為什麼iOS的CFLAGS要指定-arch=armv6而android不用?因為android的用於各個架構的編譯器是分離的,放在各自的目錄中,如toolchains/arm-linux-androideabi-4.4.3就是專用於arm的,其它x86、mips等都有對應的一套。而iOS的xcrun gcc實際上支援真機arm和模擬器x86兩種,所以它需要額外指定目標架構。
========================================
另外,luajit的編譯比較特殊,它沒有configuare,全是在makefile裡搞定配置。
所以編iOS時的命令為:
ISDK=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
ISDKVER=iPhoneOS5.1.sdk
ISDKP=$ISDK/usr/bin/
ISDKF="-arch armv6 -isysroot $ISDK/SDKs/$ISDKVER"
make HOST_CC="gcc -m32 -arch i386" CROSS=$ISDKP TARGET_FLAGS="$ISDKF" TARGET_SYS=iOS TARGET=arm
編android時:
make CROSS=/cygdrive/h/andk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi- TARGET_FLAGS=--sysroot=H:/andk/platforms/android-9/arch-arm TARGET_SYS=Linux TARGET=ARM