基于iOS5.0的MobileVLC(vlc for iOS)编译

本文地址:http://www.cnblogs.com/madongchunqiu/archive/2012/06/07/Compile-MobileVLC-in-iOS5.html

本文原发于CSDN,发表第二天就可以在Google检索到了,不过4-5天后仍然无法在百度检索到。本以为是百度和CSDN闹矛盾,不过后来发现Bing,soso,Yahoo均无法搜到,就不得不怀疑是CSDN的问题了。

所以注册了博客园,发过来试试。

【注:发布两小时后第一次搜索,发现Google和soso已经可以搜到了,但是baidu、bing和yahoo还没有反应,真汗!不过不得不说,QQ在国内总还是要高出别的互联网企业一筹的,各个产品只要做出来,都不会太丢范,这里赞一个...】

【注2:第二天可以在百度上搜到标题了,不过搜到的不是博客园的原文,而是某个网站的转载。汗!不知道百度在搞什么,和其它主流网站掐架吗?不过Bing和Yahoo到现在还没影呢。Bing好像真的挺失败的,Yahoo也早就没落。。。】

以下正文:


上篇文章:《黑苹果,iOS SDK和MobileVLC之逆旅(二) 编译MobileVLC》(http://blog.csdn.net/madongchunqiu/article/details/6707068)发出之后,陆续和不少同学们有些交流。但那毕竟只是我入门iOS平台的学习之作,故不少问题也没能帮到大家。

近来工作有了阶段性成果,可以放松一下,而且手头上面的东西也和自制VLC有那么点沾边,正巧某同学提到iOS SDK5.0上面的编译环境似乎有了不少变化,我的老文章已经无法适应新环境了,所以花了点时间,终于把这个问题搞定了。

下面开始。

 

一。编译环境:(Development Environment)

硬件平台:MBA

软件系统:Mac OS X Lion 10.7.3

开发环境:Xcode 4.2, iOS SDK 5.0

【注:开发环境不是最新的,是因为我手头的项目在那,怕升级后又要花时间调,想等到项目结尾再升到最新。】

【补注:据称,升级到Xcode4.3和iOS SDK5.1之后,开发环境最大的区别是SDK的目录由

/Developer/Platform/xxx

变成了

/Applications/Xcode.app/Contents/Developer/Platform/xxx

那么对于MobileVLC1.1.0版本而言,首先要做的,就是在源代码中,全局搜索/Developer/Platform/xxx,然后对其进行替换。或者把新目录中的东西再拷贝一份到老目录也行(似乎有些帖子就这么做的),但是考虑到既然Apple下决心换目录了,死抓着老的目录结构也没有必要。】

【补注的注:在bootstrap脚本中,会去查找/Developer/SDKs这个目录,也需要相应的修改】


二。编译的整体说明:(Overview)

总体来说,编译iOS5.0和iOS4.2的区别,在于几个编译器的“名字”变了,比如gcc-4.2和g++-4.2,在新的开发环境目录下都成了llvm-gcc-4.2或llvm-g++-4.2。据称是因为iOS SDK全面放弃使用GNU GCC的缘故。具体原因我也未查找更多资料,不过想来就是因为这些改变,所以才带来了更多的未可知变化。

 

就细节来说:编译simulator版本的MobileVLC和iOS Target版本的MobileVLC现在不能用同一个脚本了。别问我为什么会这样,我也很迷糊。如下所述

 

 

- Simulator版本的更改:

--->1. SDK版本号由3.2升级至5.0 【同iOS SDK4.2的编译修改】

--->2. 编译选项彻底区分simulator版本和iOS target版本【同iOS SDK4.2的编译修改】

--->3. 编译器名称改成:"cpp-4.2 -> llvm-cpp-4.2", "gcc-4.2 ->clang", "g++-4.2 ->llvm-g++-4.2" 【注:这里用llvm-gcc-4.2编译失败后,再改用clang成功的。原因未深究。有人说iOS SDK5.1的Simulator版本编译器目录下没有clang,这点我不甚明了。反正我iOS SDK5.0的Simulator版本编译器目录下是有clang的】

 

- iOS target版本的更改

--->1. SDK版本号由3.2升级至5.0 【同iOS SDK4.2的编译修改】

--->2. 编译选项彻底区分simulator版本和iOS target版本【同iOS SDK4.2的编译修改】

--->3. 编译器名称改成:"cpp-4.2 -> llvm-cpp-4.2", "gcc-4.2 ->llvm-gcc-4.2", "g++-4.2 -> llvm-g++-4.2" 【注:这里均使用llvm版本的编译器。请比较和Simulator版本的不同,此处使用clang反而会编译错误,原因未深究】

--->4. 链接目录参数加入:-L${IOS_SDK_ROOT}/usr/lib/system

--->5. 更改生成ffmpeg config的makefile,加入--disable-asm参数,原因后面详述

--->6. 为了编译libdvbpsi库,稍稍修改iOS SDK的源文件,在/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include中拷贝入两个新文件limits.h,原因后面详述。

下面一步步演示如何完成任务。


三。调试版本的修改过程:(Step by step for simulator version)

3.1 将MobileVLC 1.1.0的源代码(http://www.videolan.org/vlc/download-ios.html)下载到本地


3.2 创建目录(比如/VLC),并将3个源代码包解压在目录内,并依次重命名为:MediaLibraryKit, MobileVLC, vlc

 

3.3 修改MobileVLCKit(即libVLC for iOS)的脚本文件(/VLC/vlc/extras/package/ios/build_for_iOS.sh),因为有几处改动,所以不如直接拷贝我这个版本好了。【注:2处改动,一个是iOS SDK的版本号,一个是编译器的名称】

View Code
#!/bin/sh
set -e
echo "Building libvlc for the iOS"

if [ "$1" = "Simulator" ]; then
    PLATFORM="Simulator"
    TARGET="i686-apple-darwin10"
    ARCH="i386"
else
    PLATFORM="OS"
    TARGET="arm-apple-darwin10"
    ARCH="armv7"
    OPTIM="-mno-thumb"
fi

THIS_SCRIPT_PATH=`pwd`/$0

pushd `dirname $0`/http://www.cnblogs.com/..
VLCROOT=`pwd` # Let's make sure VLCROOT is an absolute path
popd
DEVROOT="/Developer/Platforms/iPhone${PLATFORM}.platform/Developer"
IOS_SDK_ROOT="${DEVROOT}/SDKs/iPhone${PLATFORM}5.0.sdk"

BUILDDIR=${VLCROOT}/build-ios-${PLATFORM}

PREFIX=${VLCROOT}/install-ios-${PLATFORM}

IOS_GAS_PREPROCESSOR="${VLCROOT}/extras/package/ios/resources/gas-preprocessor.pl"

export AR="${DEVROOT}/usr/bin/ar"
export RANLIB="${DEVROOT}/usr/bin/ranlib"
export CFLAGS="-isysroot ${IOS_SDK_ROOT} -arch ${ARCH} -miphoneos-version-min=3.2 ${OPTIM}"
export OBJCFLAGS="${CFLAGS}"
if [ "$PLATFORM" = "Simulator" ]; then
    # Use the new ABI on simulator, else we can't build
    export OBJCFLAGS="-fobjc-abi-version=2 -fobjc-legacy-dispatch ${OBJCFLAGS}"
fi
export CPPFLAGS="${CFLAGS}"
export CXXFLAGS="${CFLAGS}"
export CPP="${DEVROOT}/usr/bin/llvm-cpp-4.2"
export CXXCPP="${DEVROOT}/usr/bin/llvm-cpp-4.2"

export CC="${DEVROOT}/usr/bin/clang"
export OBJC="${DEVROOT}/usr/bin/llvm-gcc-4.2"
export CXX="${DEVROOT}/usr/bin/llvm-g++-4.2"
export LD="${DEVROOT}/usr/bin/ld"
export STRIP="${DEVROOT}/usr/bin/strip"

if [ "$PLATFORM" = "OS" ]; then
  export LDFLAGS="-L${IOS_SDK_ROOT}/usr/lib -arch ${ARCH}"
else
  export LDFLAGS="-syslibroot=${IOS_SDK_ROOT}/ -arch ${ARCH}"
fi

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:${VLCROOT}/extras/contrib/build/bin:${VLCROOT}/extras/package/ios/resources"

echo "Boostraping contribs"
pushd ${VLCROOT}/extras/contrib

# contains gas-processor.pl
export PATH=$PATH:${VLCROOT}/extras/package/ios/resources

# The contrib will read the following
export IOS_SDK_ROOT

echo "Building contrib for iOS"
./bootstrap ${TARGET} ios
make src

echo "Building contrib for current host"
./bootstrap
make

popd

if [ "$PLATFORM" = "OS" ]; then
  export AS="${IOS_GAS_PREPROCESSOR} ${CC}"
  export ASCPP="${IOS_GAS_PREPROCESSOR} ${CC}"
else
  export AS="${DEVROOT}/usr/bin/as"
  export ASCPP="${DEVROOT}/usr/bin/as"
fi


echo "Bootstraping vlc"
if ! [ -e ${VLCROOT}/configure ]; then
    ${VLCROOT}/bootstrap
fi

if [ ".$PLATFORM" != ".Simulator" ]; then
    # FIXME - Do we still need this?
    export AVCODEC_CFLAGS="-I${PREFIX}include"
    export AVCODEC_LIBS="-L${PREFIX}lib -lavcodec -lavutil -lz"
    export AVFORMAT_CFLAGS="-I${PREFIX}include"
    export AVFORMAT_LIBS="-L${PREFIX}lib -lavcodec -lz -lavutil -lavformat"
fi

mkdir -p ${BUILDDIR}
pushd ${BUILDDIR}

# Run configure only upon changes.
if [ "${VLCROOT}/configure" -nt config.log -o \
     "${THIS_SCRIPT_PATH}" -nt config.log ]; then
CONTRIB_DIR=${VLCROOT}/extras/contrib/hosts/${TARGET}/ios \
${VLCROOT}/configure \
    --prefix="$PREFIX" \
    --host="${TARGET}" \
    --enable-debug \
    --disable-shared \
    --enable-static \
    --disable-macosx \
    --disable-macosx-defaults \
    --disable-macosx-vout \
    --disable-macosx-dialog-provider \
    --disable-macosx-qtcapture \
    --disable-macosx-eyetv \
    --disable-macosx-vlc-app \
    --with-macosx-sdk=${IO_SDK_ROOT} \
    --enable-audioqueue \
    --enable-ios-vout \
    --enable-avcodec \
    --enable-avformat \
    --enable-swscale \
    --enable-faad \
    --disable-mad \
    --disable-a52 \
    --disable-fribidi \
    --disable-macosx-audio \
    --disable-qt4 --disable-skins2 \
    --disable-libgcrypt \
    --disable-remoteosd \
    --disable-vcd \
    --disable-postproc \
    --disable-vlc \
    --disable-vlm \
    --disable-httpd \
    --disable-nls \
    --disable-glx \
    --disable-visual \
    --disable-lua \
    --disable-sse \
    --disable-neon \
    --disable-mmx # MMX and SSE support requires llvm which is broken on Simulator
fi

CORE_COUNT=`sysctl -n machdep.cpu.core_count`
let MAKE_JOBS=$CORE_COUNT+1

echo "Running make -j$MAKE_JOBS"

make -j$MAKE_JOBS
make install
popd

 

3.4. 修改总脚本(/VLC/MobileVLC/buildMobileVLC.sh),将其替换成下面这个:【注:同iOS SDK4.2。其目的只是区分和细化了simulator版本和iOS target版本的参数】

View Code
#!/bin/bash


rm -rf ./MediaLibraryKit/External/MobileVLCKit
rm -rf ./MobileVLC/External/MobileVLCKit
rm -rf ./MobileVLC/External/MediaLibraryKit

if [ "$1" = "Simulator" ]; then
    pushd vlc
        echo "--==-- Build for vlc (simulator version) --==--"
        pushd extras/package/ios
            ./build_for_iOS.sh Simulator
        popd

        echo "--==-- Build for vlc-MobileVLCKit (simulator version) --==--"
        pushd projects/macosx/framework
            xcodebuild -project MobileVLCKit.xcodeproj -target "Aggregate static plugins" -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386 
            xcodebuild -project MobileVLCKit.xcodeproj -target "MobileVLCKit" -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
        popd
    popd

    echo "--==-- Build for MediaLibraryKit (simulator version) --==--"
    pushd MediaLibraryKit
        ln -s http://www.cnblogs.com/vlc/projects/macosx/framework/build/Release-iphonesimulator External/MobileVLCKit
        xcodebuild -project MobileMediaLibraryKit.xcodeproj -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
    popd

    echo "--==-- Build for MobileVLC (simulator version) --==--"
    pushd MobileVLC
        ln -s http://www.cnblogs.com/vlc/projects/macosx/framework/build/Release-iphonesimulator External/MobileVLCKit
        ln -s http://www.cnblogs.com/MediaLibraryKit/build/Release-iphonesimulator External/MediaLibraryKit
        xcodebuild -project MobileVLC.xcodeproj -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
    popd
else
    pushd vlc
        echo "--==-- Build for vlc (os version) --==--"
        pushd extras/package/ios
            ./build_for_iOS.sh
        popd

        echo "--==-- Build for vlc-MobileVLCKit (os version) --==--"
        pushd projects/macosx/framework
            xcodebuild -project MobileVLCKit.xcodeproj -target "Aggregate static plugins" -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7
            xcodebuild -project MobileVLCKit.xcodeproj -target "MobileVLCKit" -configuration "Release"  -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
        popd
    popd

    echo "--==-- Build for MediaLibraryKit (os version) --==--"
    pushd MediaLibraryKit
        ln -s http://www.cnblogs.com/vlc/projects/macosx/framework/build/Release-iphoneos External/MobileVLCKit
        xcodebuild -project MobileMediaLibraryKit.xcodeproj -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
    popd

    echo "--==-- Build for MobileVLC (os version) --==--"
    pushd MobileVLC
        ln -s http://www.cnblogs.com/vlc/projects/macosx/framework/build/Release-iphoneos External/MobileVLCKit
        ln -s http://www.cnblogs.com/MediaLibraryKit/build/Release-iphoneos External/MediaLibraryKit
        xcodebuild -project MobileVLC.xcodeproj -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
    popd

fi

 

3.5. 运行脚本进行编译

cd /VLC
./MobileVLC/buildMobileVLC.sh Simulator

 

3.6. 多运行几遍保证各个编译命令都是"Build SUCCEEDED"。需要多编译几次的原因我这次看了下,好像有这几种情况

- a) FFMPEG库打patch时出错。这个似乎不影响使用。第二次编译可以通过

- b) faad2库下载失败。可以回看log,看下载进度是不是到了100%,如果不是,去/VLC/vlc/extras/contrib/src-i686-apple-darwin10-ios/src/目录下,将下载的faad2-x.x.tar.gz和faad2库删掉。再重新编译。别的几个库同理。下载如问题多多,有必要时请加载V-PN...

- c) 库下载解压后再编译时环境配置不到位。这时重新编译就可以发现会新编译一些东西,然后就可以过了。应该是脚本不够完善的缘故。

 

然后,就应该可以在simulator下调试了。不过很雷人的是VLC在调试界面下,无法导入文件,因此也没法有效调试。不过有个同学提到过可以hardcode入流媒体的链接,这不失为一种方法。不过我没有试过。


四。iOS目标版本的修改过程:(Step by step for iOS device version)

4.1 将MobileVLC 1.1.0的源代码(http://www.videolan.org/vlc/download-ios.html)下载到本地


4.2 创建目录(比如/VLC),并将3个源代码包解压在目录内,并依次重命名为:MediaLibraryKit, MobileVLC, vlc

 

4.3 修改MobileVLCKit(即libVLC for iOS)的脚本文件(/VLC/vlc/extras/package/ios/build_for_iOS.sh),因为有几处改动,所以不如直接拷贝我这个版本好了。【注:3处改动,一是iOS SDK的版本号,二是编译器的名称,三是加入了新的链接目录】

View Code
#!/bin/sh
set -e

echo "Building libvlc for the iOS"

if [ "$1" = "Simulator" ]; then
    PLATFORM="Simulator"
    TARGET="i686-apple-darwin10"
    ARCH="i386"
else
    PLATFORM="OS"
    TARGET="arm-apple-darwin10"
    ARCH="armv7"
    OPTIM="-mno-thumb"
fi

THIS_SCRIPT_PATH=`pwd`/$0

pushd `dirname $0`/http://www.cnblogs.com/..
VLCROOT=`pwd` # Let's make sure VLCROOT is an absolute path
popd
DEVROOT="/Developer/Platforms/iPhone${PLATFORM}.platform/Developer"
IOS_SDK_ROOT="${DEVROOT}/SDKs/iPhone${PLATFORM}5.0.sdk"

BUILDDIR=${VLCROOT}/build-ios-${PLATFORM}

PREFIX=${VLCROOT}/install-ios-${PLATFORM}

IOS_GAS_PREPROCESSOR="${VLCROOT}/extras/package/ios/resources/gas-preprocessor.pl"

export AR="${DEVROOT}/usr/bin/ar"
export RANLIB="${DEVROOT}/usr/bin/ranlib"
export CFLAGS="-isysroot ${IOS_SDK_ROOT} -arch ${ARCH} -miphoneos-version-min=5.0 ${OPTIM}"
export OBJCFLAGS="${CFLAGS}"
if [ "$PLATFORM" = "Simulator" ]; then
    # Use the new ABI on simulator, else we can't build
    export OBJCFLAGS="-fobjc-abi-version=2 -fobjc-legacy-dispatch ${OBJCFLAGS}"
fi
export CPPFLAGS="${CFLAGS}"
export CXXFLAGS="${CFLAGS}"
export CPP="${DEVROOT}/usr/bin/llvm-cpp-4.2"
export CXXCPP="${DEVROOT}/usr/bin/llvm-cpp-4.2"

export CC="${DEVROOT}/usr/bin/llvm-gcc-4.2"
export OBJC="${DEVROOT}/usr/bin/llvm-gcc-4.2"
export CXX="${DEVROOT}/usr/bin/llvm-g++-4.2"
export LD="${DEVROOT}/usr/bin/ld"
export STRIP="${DEVROOT}/usr/bin/strip"

if [ "$PLATFORM" = "OS" ]; then
  export LDFLAGS="-L${IOS_SDK_ROOT}/usr/lib -L${IOS_SDK_ROOT}/usr/lib/system -arch ${ARCH}"
else
  export LDFLAGS="-syslibroot=${IOS_SDK_ROOT}/ -arch ${ARCH}"
fi

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:${VLCROOT}/extras/contrib/build/bin:${VLCROOT}/extras/package/ios/resources"

echo "Boostraping contribs"
pushd ${VLCROOT}/extras/contrib

# contains gas-processor.pl
export PATH=$PATH:${VLCROOT}/extras/package/ios/resources

# The contrib will read the following
export IOS_SDK_ROOT

echo "Building contrib for iOS"
./bootstrap ${TARGET} ios
make src

echo "Building contrib for current host"
./bootstrap
make

popd

if [ "$PLATFORM" = "OS" ]; then
  export AS="${IOS_GAS_PREPROCESSOR} ${CC}"
  export ASCPP="${IOS_GAS_PREPROCESSOR} ${CC}"
else
  export AS="${DEVROOT}/usr/bin/as"
  export ASCPP="${DEVROOT}/usr/bin/as"
fi


echo "Bootstraping vlc"
if ! [ -e ${VLCROOT}/configure ]; then
    ${VLCROOT}/bootstrap
fi

if [ ".$PLATFORM" != ".Simulator" ]; then
    # FIXME - Do we still need this?
    export AVCODEC_CFLAGS="-I${PREFIX}include"
    export AVCODEC_LIBS="-L${PREFIX}lib -lavcodec -lavutil -lz"
    export AVFORMAT_CFLAGS="-I${PREFIX}include"
    export AVFORMAT_LIBS="-L${PREFIX}lib -lavcodec -lz -lavutil -lavformat"
fi

mkdir -p ${BUILDDIR}
pushd ${BUILDDIR}

# Run configure only upon changes.
if [ "${VLCROOT}/configure" -nt config.log -o \
     "${THIS_SCRIPT_PATH}" -nt config.log ]; then
CONTRIB_DIR=${VLCROOT}/extras/contrib/hosts/${TARGET}/ios \
${VLCROOT}/configure \
    --prefix="$PREFIX" \
    --host="${TARGET}" \
    --enable-debug \
    --disable-shared \
    --enable-static \
    --disable-macosx \
    --disable-macosx-defaults \
    --disable-macosx-vout \
    --disable-macosx-dialog-provider \
    --disable-macosx-qtcapture \
    --disable-macosx-eyetv \
    --disable-macosx-vlc-app \
    --with-macosx-sdk=${IO_SDK_ROOT} \
    --enable-audioqueue \
    --enable-ios-vout \
    --enable-avcodec \
    --enable-avformat \
    --enable-swscale \
    --enable-faad \
    --disable-mad \
    --disable-a52 \
    --disable-fribidi \
    --disable-macosx-audio \
    --disable-qt4 --disable-skins2 \
    --disable-libgcrypt \
    --disable-remoteosd \
    --disable-vcd \
    --disable-postproc \
    --disable-vlc \
    --disable-vlm \
    --disable-httpd \
    --disable-nls \
    --disable-glx \
    --disable-visual \
    --disable-lua \
    --disable-sse \
    --disable-neon \
    --disable-mmx # MMX and SSE support requires llvm which is broken on Simulator
fi

CORE_COUNT=`sysctl -n machdep.cpu.core_count`
let MAKE_JOBS=$CORE_COUNT+1

echo "Running make -j$MAKE_JOBS"

make -j$MAKE_JOBS
make install
popd

 

4.4. 修改总脚本(/VLC/MobileVLC/buildMobileVLC.sh),将其替换成下面这个:【注:同iOS SDK4.2,也同上面的Simulator版本,其目的只是区分和细化了simulator版本和iOS target版本的参数】

View Code
#!/bin/bash


rm -rf ./MediaLibraryKit/External/MobileVLCKit
rm -rf ./MobileVLC/External/MobileVLCKit
rm -rf ./MobileVLC/External/MediaLibraryKit

if [ "$1" = "Simulator" ]; then
    pushd vlc
        echo "--==-- Build for vlc (simulator version) --==--"
        pushd extras/package/ios
            ./build_for_iOS.sh Simulator
        popd

        echo "--==-- Build for vlc-MobileVLCKit (simulator version) --==--"
        pushd projects/macosx/framework
            xcodebuild -project MobileVLCKit.xcodeproj -target "Aggregate static plugins" -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386 
            xcodebuild -project MobileVLCKit.xcodeproj -target "MobileVLCKit" -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
        popd
    popd

    echo "--==-- Build for MediaLibraryKit (simulator version) --==--"
    pushd MediaLibraryKit
        ln -s http://www.cnblogs.com/vlc/projects/macosx/framework/build/Release-iphonesimulator External/MobileVLCKit
        xcodebuild -project MobileMediaLibraryKit.xcodeproj -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
    popd

    echo "--==-- Build for MobileVLC (simulator version) --==--"
    pushd MobileVLC
        ln -s http://www.cnblogs.com/vlc/projects/macosx/framework/build/Release-iphonesimulator External/MobileVLCKit
        ln -s http://www.cnblogs.com/MediaLibraryKit/build/Release-iphonesimulator External/MediaLibraryKit
        xcodebuild -project MobileVLC.xcodeproj -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
    popd
else
    pushd vlc
        echo "--==-- Build for vlc (os version) --==--"
        pushd extras/package/ios
            ./build_for_iOS.sh
        popd

        echo "--==-- Build for vlc-MobileVLCKit (os version) --==--"
        pushd projects/macosx/framework
            xcodebuild -project MobileVLCKit.xcodeproj -target "Aggregate static plugins" -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7
            xcodebuild -project MobileVLCKit.xcodeproj -target "MobileVLCKit" -configuration "Release"  -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
        popd
    popd

    echo "--==-- Build for MediaLibraryKit (os version) --==--"
    pushd MediaLibraryKit
        ln -s http://www.cnblogs.com/vlc/projects/macosx/framework/build/Release-iphoneos External/MobileVLCKit
        xcodebuild -project MobileMediaLibraryKit.xcodeproj -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
    popd

    echo "--==-- Build for MobileVLC (os version) --==--"
    pushd MobileVLC
        ln -s http://www.cnblogs.com/vlc/projects/macosx/framework/build/Release-iphoneos External/MobileVLCKit
        ln -s http://www.cnblogs.com/MediaLibraryKit/build/Release-iphoneos External/MediaLibraryKit
        xcodebuild -project MobileVLC.xcodeproj -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
    popd

fi

 

4.5 修改生成FFMpeg的config.h的Makefile文件,禁用汇编。具体原因见下面的纠错Troubleshooting章节。

Makefile位于:/VLC/vlc/extras/contrib/src目录下

改动方式:搜寻关键字“FFMPEGCONF”,使其加入"--disable-asm"参数。我的方法是在搜寻到关键字"FFMPEGCONF"的第一个地方,将

FFMPEGCONF = 

改成

FFMPEGCONF = --disable-asm

【注:其实改在ffmpeg编译章节那里会更合适,不过反正作用是一样的。另:由于Makefile文件太大,就不贴原文了。】

 

4.6 为了编译libdvbpsi库,稍稍修改iOS SDK的源文件。这是因为编译时会报错说找不到"i386/limits.h",所以需要把这个文件拷贝到他的搜寻目录中去。具体原因见后面的纠错Troubleshotting章节。

- a) 找到目录:/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include

- b) 在其中新建目录:i386

- c) 全局搜索某个i386目录下的limits.h和_limits.h文件,并将搜索到的这两个文件拷贝入刚才创建的目录中。

【注:修改系统目录,有风险!请谨慎!】

【注2:新建目录时会提示需要administrator授权,别怕,只是新加了两个文件进去而已】

【注3:在新加入的目录中,留下个人醒目标志,以后好搜索还原】

 

4.7. 运行脚本进行编译

cd /VLC
./MobileVLC/buildMobileVLC.sh

 

4.8. 多运行几遍保证各个编译命令都是"Build SUCCEEDED"。需要多编译几次的原因我这次看了下,好像有这几种情况

- a) FFMPEG库打patch时出错。这个似乎不影响使用。第二次编译可以通过

- b) faad2库下载失败。可以回看log,看下载进度是不是到了100%,如果不是,去/VLC/vlc/extras/contrib/src-arm-apple-darwin10-ios/src/目录下,将下载的faad2-x.x.tar.gz和faad2库删掉。再重新编译。别的几个库同理。下载如问题多多,有必要时请加载V-PN...

- c) 库下载解压后再编译时环境配置不到位。这时重新编译就可以发现会新编译一些东西,然后就可以过了。应该是脚本不够完善的缘故。

 

然后,就可以在下载到真机进行调试了。程序下载到iOS device后,debugger会报错,然后弹窗口说调试失败,未深究原因。不过MobileVLC这时已经可以直接在iOS device里面使用了。比如我向ipad的VLC中导入了rmvb/asf/mp4/mkv类型文件各一个,均可以播放哦~如图:

 

【注:由于去掉了FFMpeg的汇编,据称解码效率会有比较大的牺牲】

【注2:临时找的几个视频播放都还不错,mp3放进去没反应】


五。纠错 (TroubleShooting)

1. 一些基本原因,请参考上一篇同章节:《黑苹果,iOS SDK和MobileVLC之逆旅(二) 编译MobileVLC》 (http://blog.csdn.net/madongchunqiu/article/details/6707068)

2. 关于FFMpeg基于iOS5.0的编译问题。Google上有很多相关帖子。大致有如下原因:

- a) 链接目录不对,导致出错:“ld: in /usr/lib/system/libcache.dylib, missing required architecture armv7 in file for architecture armv7”,请参考此文:StackOverflow - building MobileVLC -> armc7 + ffmpeg issue (http://stackoverflow.com/questions/6320053/building-mobilevlc-armc7-ffmpeg-issue)

- b) 编译器选择错误,导致出错:"ld: library not found for -lcrt1.10.6.0"。clang/gcc/llvm-gcc等等,都试了试。

- c) 未禁用inline asm或者asm,导致gas-preprocessor.pl处理时出错。原因似乎是因为编译器和汇编的指令集32bit/64bit不一致。下面这几篇文章中有比较详细的描述:StackOverflow - FFmpeg for iOS5 (http://stackoverflow.com/questions/8323672/ffmpeg-for-ios5),yuvi / gas-preprocessor issue #16 (https://github.com/yuvi/gas-preprocessor/issues/16),倾情奉献ios5.0编译ffmpeg,真机ok! (http://www.cocoachina.com/bbs/read.php?tid=98563)

- d) 在xcode3.2.5 / iOS SDK4.2编译环境下,FFMpeg是没有这些乱七八糟的问题的。

3. 关于libdvbpsi库的编译问题,在SDK中居然缺乏必要的文件。这个问题应该也可以通过加入新的搜索目录来实现,但是我还是野蛮了一把直接改了SDK。这篇文章里面有比较详细的说明:multiple arch flags won't work with -E (http://lists.macosforge.org/pipermail/macports-dev/2011-February/013745.html)

4. 关于编译中下载第三方库并进行编译时,容易出错的原因:可能是库文件包下载不完整。我有好几次下载到一半就中断下载了,或者下载了半个小时没反应。。。最后发现还是V-PN比较好用。这种问题的解决方法就是多编译几次,或者删了下载的东西再重新编译,甚或新建一个VLC目录重新开始。


六。遗留 (TO DO)

等我的iOS SDK升级到5.1,还需要试试上面的东西管不管用。当然,如果哪位仁兄能帮我试试,然后给我一点反馈就再好不过了。

然后一直以来都是编译的MobileVLC1.1.0版本,也不清楚git上面的最新MobileVLC版本会如何。不知道VLC因为license问题无法在app store上上架,是否会影响其团队在iOS平台上继续开发。

 

七。参考文章 (References)

1. StackOverflow - building MobileVLC -> armc7 + ffmpeg issue (http://stackoverflow.com/questions/6320053/building-mobilevlc-armc7-ffmpeg-issue)

2. StackOverflow - FFmpeg for iOS5 (http://stackoverflow.com/questions/8323672/ffmpeg-for-ios5)

3. yuvi / gas-preprocessor issue #16 (https://github.com/yuvi/gas-preprocessor/issues/16)

4. 倾情奉献ios5.0编译ffmpeg,真机ok!(http://www.cocoachina.com/bbs/read.php?tid=98563)

5. multiple arch flags won't work with -E (http://lists.macosforge.org/pipermail/macports-dev/2011-February/013745.html)

 

posted @ 2012-06-07 14:02  码懂  阅读(6671)  评论(9编辑  收藏  举报