我一直在尝试使用Mountain Lion中的iOS 5.1 SDK为armv6,armv6和i386交叉编译libogg。 Libogg使用autoconf,我和其他几个库也遇到了类似的问题。我从here中选择了一个简洁的小交叉编译脚本。我不得不更新它以找到SDK的位置。
GLOBAL_OUTDIR="`pwd`/dependencies"
mkdir -p $GLOBAL_OUTDIR/include $GLOBAL_OUTDIR/lib
OUTDIR="./outdir"
OGG_LIB="`pwd`/libogg-1.3.0"
IOS_BASE_SDK="5.1"
IOS_DEPLOY_TGT="3.2"
setenv_all()
{
# Add internal libs
export CFLAGS="$CFLAGS -I$GLOBAL_OUTDIR/include -L$GLOBAL_OUTDIR/lib"
export CXX="$DEVROOT/usr/bin/llvm-g++-4.2"
export CC="$DEVROOT/usr/bin/llvm-gcc-4.2"
export LD=$DEVROOT/usr/bin/ld
export AR=$DEVROOT/usr/bin/ar
export AS=$DEVROOT/usr/bin/as
export NM=$DEVROOT/usr/bin/nm
export RANLIB=$DEVROOT/usr/bin/ranlib
export LDFLAGS="-L$SDKROOT/usr/lib/"
export CPPFLAGS=$CFLAGS
export CXXFLAGS=$CFLAGS
}
setenv_arm6()
{
unset DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS
export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS$IOS_BASE_SDK.sdk
export CFLAGS="-arch armv6 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/"
setenv_all
}
setenv_arm7()
{
unset DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS
export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneOS$IOS_BASE_SDK.sdk
export CFLAGS="-arch armv7 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT -I$SDKROOT/usr/include/"
setenv_all
}
setenv_i386()
{
unset DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM CXXCPP RANLIB LDFLAGS CPPFLAGS CXXFLAGS
export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer
export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator$IOS_BASE_SDK.sdk
export CFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot $SDKROOT -miphoneos-version-min=$IOS_DEPLOY_TGT"
setenv_all
}
create_outdir_lipo()
{
for lib_i386 in `find $LOCAL_OUTDIR/i386 -name "lib*\.a"`; do
lib_arm6=`echo $lib_i386 | sed "s/i386/arm6/g"`
lib_arm7=`echo $lib_i386 | sed "s/i386/arm7/g"`
lib=`echo $lib_i386 | sed "s/i386\///g"`
lipo -arch armv6 $lib_arm6 -arch armv7 $lib_arm7 -arch i386 $lib_i386 -create -output $lib
done
}
merge_libfiles()
{
DIR=$1
LIBNAME=$2
cd $DIR
for i in `find . -name "lib*.a"`; do
$AR -x $i
done
$AR -r $LIBNAME *.o
rm -rf *.o __*
cd -
}
然后构建ogg库。
## libogg
cd $OGG_LIB
rm -rf $OUTPUT_DIR
mkdir -p $OUTDIR/arm6 $OUTDIR/arm7 $OUTDIR/i386
## Build for armv6
make clean 2> /dev/null
make distclean 2> /dev/null
setenv_arm6
./configure --host=arm-apple-darwin6 --enable-shared=no
make
cp /src/.libs/libogg.a $OUTDIR/arm6
## Build for armv7
make clean 2> /dev/null
make distclean 2> /dev/null
setenv_arm7
./configure --host=arm-apple-darwin7 --enable-shared=no
make
cp src/.libs/libogg.a $OUTDIR/arm7
## Build for iPhone simulator
make clean 2> /dev/null
setenv_i386
./configure
make -j4
cp src/.libs/libogg.a $OUTDIR/i386
## Stich it altogether in a fat .a file.
create_outdir_lipo
无论如何,在构建armv6和armv7时,configure会发现编译器和sdk没问题,编译阶段也顺利完成。但他们都没有联系。 armv7 build会发出错误。
ld: in section __TEXT,__text reloc 1: unknown relocation type 9 for architecture armv7 collect2: ld returned 1 exit status
当我用lipo测试输出二进制文件时:
$ lipo -info libogg.a
lipo: archive with no architecture specification: libogg.a (can't determine architecture for it)
奇怪的是i386似乎编译得很完美,(我已经在模拟器中尝试过了,一切都很好)。
关于我可以做些什么来尝试解决这个问题的建议,或者至少我应该开始寻找的地方。对于大量代码转储感到抱歉,谢谢。
答案 0 :(得分:4)
我能够通过将编译的优化级别设置为-O3
而不是-O4
来解决此问题。使用-O4
文件输出似乎无法被lipo
识别(甚至file
报告为data
而不是Mach-O object arm
)。
更新:似乎有不少人在编译Ogg Vorbis时遇到了困难。我已经使我的构建可用。请参阅:Precompiled Ogg Vorbis Libraries for iOS。