使用Xcode5.1错误编译适用于iOS的FFmpeg

时间:2014-04-18 10:01:55

标签: ios xcode macos ffmpeg cross-compiling

环境:Mac OS X 10.9.2,Xcode 5.1。构建shell脚本如下:

#!/bin/sh

# OS X 10.9.2, Xcode 5.1

set -ex

VERSION="2.2.1"
SDKVERSION="7.1"
BUILDDIR=`pwd`
DESTDIR="ffmpeg-built"
OUTPUTDIR="dependencies"
DEVELOPER=`xcode-select -print-path`
GASPREPROCESSOR="gas-preprocessor.pl"
ARCHS="i386 x86_64 armv7 armv7s arm64"

cp $GASPREPROCESSOR /usr/local/bin

rm -rf $DESTDIR
mkdir $DESTDIR

rm -rf $OUTPUTDIR
mkdir $OUTPUTDIR
mkdir -p $OUTPUTDIR/bin
mkdir -p $OUTPUTDIR/include
mkdir -p $OUTPUTDIR/lib

if [ ! -e "ffmpeg-$VERSION.tar.bz2" ]; then
    curl -LO http://ffmpeg.org/releases/ffmpeg-$VERSION.tar.bz2
fi

tar jxf ffmpeg-$VERSION.tar.bz2
cd "ffmpeg-$VERSION"

set +e
CCACHE=`which ccache`
if [ $? == "0" ]; then
    CCACHE="$CCACHE "
else
    CCACHE=""
fi
set -e

for ARCH in $ARCHS;
do
    mkdir -p ../$DESTDIR/$ARCH

    make distclean

    IOSMV="-miphoneos-version-min=4.3"
    if [ $ARCH == "arm64" ]; then
        IOSMV="-miphoneos-version-min=7.0"
    fi
    CONFIG="--disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile"

    if [ "$ARCH" == "i386" ];
    then
        PLATFORM="iPhoneSimulator"
        EXTRA_CONFIG="--arch=i386 --target-os=darwin --cpu=i386 --disable-asm --enable-pic"
        EXTRA_CFLAGS="-arch i386"
        EXTRA_LDFLAGS="-I$DEVELOPER/Platforms/$PLATFORM.platform/Developer/SDKs/$PLATFORM$SDKVERSION.sdk/usr/lib -mfpu=neon"
    else
        PLATFORM="iPhoneOS"
        EXTRA_CONFIG="--arch=arm --target-os=darwin --cpu=cortex-a8 --disable-armv5te --enable-pic"
        EXTRA_CFLAGS="-w -arch $ARCH -mfpu=neon"
        EXTRA_LDFLAGS="-mfpu=neon"
    fi

    ./configure --prefix=$BUILDDIR/$DESTDIR/$ARCH --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-iconv --disable-bzlib --enable-avresample --sysroot="$DEVELOPER/Platforms/$PLATFORM.platform/Developer/SDKs/$PLATFORM$SDKVERSION.sdk" --cc="$DEVELOPER/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" --as='/usr/local/bin/$GASPREPROCESSOR' --extra-cflags="$EXTRA_CFLAGS -miphoneos-version-min=$SDKVERSION -I$BUILDDIR/$OUTPUTDIR/include" --extra-ldflags="-arch $ARCH $EXTRA_LDFLAGS -isysroot $DEVELOPER/Platforms/$PLATFORM.platform/Developer/SDKs/$PLATFORM$SDKVERSION.sdk -miphoneos-version-min=$SDKVERSION -L$BUILDDIR/$OUTPUTDIR/lib" $EXTRA_CONFIG --enable-pic --extra-cxxflags="$CPPFLAGS -I$BUILDDIR/$OUTPUTDIR/include -isysroot $DEVELOPER/Platforms/$PLATFORM.platform/Developer/SDKs/$PLATFORM$SDKVERSION.sdk"

    make
    make install
done
make distclean

cd ..
mkdir -p $DESTDIR/universal/lib
cd $DESTDIR/i386/lib

for FILE in *.a;
do
    INPUT=""
    for ARCH in $ARCHS;
    do
        INPUT="$INPUT $DESTDIR/$ARCH/lib/$FILE"
    done
    lipo -create $INPUT -output $DESTDIR/universal/lib/$FILE
done

但终端记录:

+ VERSION=2.2.1
+ SDKVERSION=7.1
++ pwd
+ BUILDDIR=/Users/Smeegol/Desktop/FFmpeg
+ DESTDIR=ffmpeg-built
++ xcode-select -print-path
+ DEVELOPER=/Applications/Xcode.app/Contents/Developer
+ ARCHS='i386 x86_64 armv7 armv7s arm64'
+ rm -rf ffmpeg-built
+ mkdir ffmpeg-built
+ '[' '!' -e ffmpeg-2.2.1.tar.bz2 ']'
+ tar jxf ffmpeg-2.2.1.tar.bz2
+ cd ffmpeg-2.2.1
+ set +e
++ which ccache
+ CCACHE=
+ '[' 1 == 0 ']'
+ CCACHE=
+ set -e
+ for ARCH in '$ARCHS'
+ mkdir -p ../ffmpeg-built/i386
+ IOSMV=-miphoneos-version-min=4.3
+ '[' i386 == arm64 ']'
+ CONFIG='--disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile'
+ '[' i386 == i386 ']'
+ PLATFORM=iPhoneSimulator
+ EXTRA_CONFIG='--arch=i386 --target-os=darwin --cpu=i386 --enable-pic --disable-asm'
+ EXTRA_CFLAGS='-arch i386 -mfpu=neon -miphoneos-version-min=4.3'
+ ./configure --prefix=/Users/Smeegol/Desktop/FFmpeg/ffmpeg-built/i386 --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --enable-avresample --enable-cross-compile --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk --cc=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang --extra-cflags=-arch i386 -mfpu=neon -miphoneos-version-min=4.3 '--extra-ldflags=-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -miphoneos-version-min=4.3' --arch=i386 --target-os=darwin --cpu=i386 --enable-pic --disable-asm
Unknown option "i386".
See ./configure --help for available options.

为什么Unknown option "i386".

1 个答案:

答案 0 :(得分:0)

  

- extra-cflags = -arch i386 -mfpu = neon -miphoneos-version-min = 4.3

这里有两件事似乎不对。

首先,config.log显示--extra-cflags=<args>未正确转义。因此,FFmpeg的./configure脚本会看到--extra-cflags=-archi386-mfpu=neon; <{1}}单独不是脚本的有效标志,因此失败。

您可以将脚本与the one I maintain on github进行比较。我想知道如果你在脚本中使用变量扩展而不是变量替换会发生什么? e.g。

i386

...尝试:

--extra-cflags="$EXTRA_CFLAGS -miphoneos-versi....

其次,--extra-cflags="${EXTRA_CFLAGS} -miphoneos-versi....-mfpu=neon一起没有意义。看起来这个脚本正在经历包含-arch i386而不是PLATFORM="iPhoneOS"的大if语句的分支。那只是不起作用。

所以,我不是百分之百确定修复,但这些是你的一些问题。