本文地址: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的版本號,一個是編譯器的名稱】

#!/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版本的參數】

#!/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的版本號,二是編譯器的名稱,三是加入了新的鏈接目錄】

#!/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版本的參數】

#!/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)