ios/android交叉编译参数设置

  很多开源库的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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值