最近因工做須要使用到opencore-amr-iOS庫,進行caf格式與amr格式互轉, 但當前的lib是不支持bitcode選項的, 所以我須要將opencore-amr-iOS從新編一個支持bitcode的版本. html
因而先從github中下載對應的源碼, 誰知道這個源碼已經4年沒有更新了, 事已至此只能碰碰運氣看可否正常工做. 果不其然, 自動編譯的腳本只支持到了XCode6, 在XCode8環境下編譯不經過.ios
沒辦法只能google看看有沒有碰到一樣問題的哥們, 還真能找個一個哥們也在作一樣的事情, 附上連接:http://www.code4app.com/blog-721976-132.html; 心中一陣竊喜, 我按照他的步驟結果失敗了, 報了好多錯誤. 好在咱不是輕易放棄的人, 有問題一個一個解決唄.c++
首先碰到的是:git
checking whether we are cross compiling... configure: error: in `/Users/tbwx/test/opencore-amr-iOS': configure: error: cannot run C++ compiled programs. If you meant to cross compile, use `--host'. See `config.log' for more details
通過一番測試,修改build_ios_xcode6.sh文件中41行: ./configure
--prefix=$DEST
--disable-shared 在configure \下面增長 --host=$arch
OK, 編譯經過了.github
而後就是解決bitcode的問題了, 根據上面博客中的內容,重要的是在編譯選項中增長bitcode相關的開關, 因而乎,在編譯選項中增長了可是又報錯了:xcode
configure: error: in `/Users/tbwx/test/opencore-amr-iOS': configure: error: C++ compiler cannot create executables See `config.log' for more details
查看config.log中的日誌:app
clang: error: argument to '-V' is missing (expected 1 value) clang: error: no input files configure:3469: $? = 1
看來問題出在config這個文件裏, 從文件裏找到-V的地方,通通刪掉,再來一次. 結果仍是報錯:iphone
platform/Developer/SDKs/iPhoneOS10.2.sdk -isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk/usr/include -fembed-bitcode -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk conftest.cpp >&5 clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of iOS 7 ld: only one -syslibroot is accepted for bitcode bundle for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)
看來這原始的腳本兼容性不行啊, 繼續改,將build_ios_xcode6.sh中的第31行,-syslibroot,$SDK的編譯選項刪除, go on. ....編譯中..... 經過了!!測試
將lib文件替換原來的, 在將項目的bitcode選項改成YES, 運行正常!ui
附上最終的編譯文件:
#!/bin/sh set -xe DEVELOPER=`xcode-select -print-path` DEST=`pwd .`"/opencore-amr-iOS" ARCHS="i386 x86_64 armv7 armv7s arm64" LIBS="libopencore-amrnb.a libopencore-amrwb.a" # Note that AMR-NB is for narrow band http://en.wikipedia.org/wiki/Adaptive_Multi-Rate_audio_codec # for AMR-WB encoding, refer to http://sourceforge.net/projects/opencore-amr/files/vo-amrwbenc/ # or AMR Codecs as Shared Libraries http://www.penguin.cz/~utx/amr mkdir -p $DEST ./configure for arch in $ARCHS; do make clean IOSMV=" -miphoneos-version-min=7.0" case $arch in arm*) if [ $arch == "arm64" ] then IOSMV=" -miphoneos-version-min=7.0" fi echo "Building opencore-amr for iPhoneOS $arch ****************" PATH=`xcodebuild -version -sdk iphoneos PlatformPath`"/Developer/usr/bin:$PATH" \ SDK=`xcodebuild -version -sdk iphoneos Path` \ CXX="xcrun --sdk iphoneos clang++ -arch $arch $IOSMV --sysroot=$SDK -isystem $SDK/usr/include -fembed-bitcode" \ LDFLAGS="-Wl" \ ./configure \ --host=arm-apple-darwin \ --prefix=$DEST \ --disable-shared ;; *) echo "Building opencore-amr for iPhoneSimulator $arch *****************" PATH=`xcodebuild -version -sdk iphonesimulator PlatformPath`"/Developer/usr/bin:$PATH" \ CXX="xcrun --sdk iphonesimulator clang++ -arch $arch $IOSMV -fembed-bitcode" \ ./configure \ --host=$arch \ --prefix=$DEST \ --disable-shared ;; esac make -j3 make install for i in $LIBS; do mv $DEST/lib/$i $DEST/lib/$i.$arch done done echo "Merge into universal binary." for i in $LIBS; do input="" for arch in $ARCHS; do input="$input $DEST/lib/$i.$arch" done xcrun lipo -create -output $DEST/lib/$i $input done