为 iOS 交叉编译 libogg [英] Cross Compiling libogg for iOS

查看:20
本文介绍了为 iOS 交叉编译 libogg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 Mountain Lion 中的 iOS 5.1 SDK 为 armv6、armv6 和 i386 交叉编译 libogg.Libogg 使用 autoconf,我也遇到了与其他一些库非常相似的问题.我从 这里.我不得不对其进行一些更新才能找到 SDK 的位置.

I've been trying to cross compile libogg for armv6, armv6 and i386 using the iOS 5.1 SDK in Mountain Lion. Libogg uses autoconf, and I've been having pretty similar issues with a few other libraries as well. I picked up a neat little cross-compiling script from here. I had to update it a bit to find the location of the SDK's.

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 库.

And then to build the ogg library.

## 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 构建会抛出错误.

Anyway, when building armv6 and armv7, configure finds the compiler's and sdk's okay , and the compiling stage goes off without a hitch. But they both fail to link. The armv7 build spits out the error.

ld: in section __TEXT,__text reloc 1: unknown relocation type 9 for architecture armv7 collect2: ld returned 1 exit status

当我用 lipo 测试输出二进制文件时:

And when I test the output binary with lipo :

$ lipo -info libogg.a
lipo: archive with no architecture specification: libogg.a (can't determine architecture for it)

奇怪的是 i386 似乎编译完美,(我在模拟器中试过,一切正常).

What is strange is i386 seems to compile perfectly, (I've tried it in the simulator and all is okay).

关于我可以做些什么来尝试解决这个问题的任何建议,或者至少我应该从哪里开始寻找.很抱歉大量代码转储,谢谢.

Any suggestions on what I can do to try and fix this, or a least where I should start looking. Sorry for the massive code dumps, and thanks.

推荐答案

我能够通过将编译的优化级别设置为 -O3 而不是 -O4.使用 -O4 文件输出似乎无法被 lipo 识别(甚至 file 将它们报告为 data而不是 Mach-O 对象臂).

I was able to solve this by setting the optimization level on the compile to -O3 instead of -O4. With -O4 the files output do not seem to be recognizable to lipo (and even file reports them as data instead of Mach-O object arm).

更新: 似乎有不少人在编译 Ogg Vorbis 时遇到了困难.我已经使我的构建可用.请参阅:适用于 iOS 的预编译 Ogg Vorbis 库.

Update: It seems quite a few people are encountering difficulty compiling Ogg Vorbis. I have made my build available. See: Precompiled Ogg Vorbis Libraries for iOS.

这篇关于为 iOS 交叉编译 libogg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆