【轉】iOS lame編譯 arm64 armv7s armv7 x86_64 i386指令集

原文出至 http://blog.csdn.net/vieri_ch/article/details/40650467ios

最近升級了系統到Mac OS X 10.10 而且更新了XCode6.1和iOS 8.1git

以前app用到的libmp3lame.a靜態庫,也要支持64位的模擬器(x86_64)和64位的真機(arm64)指令集。須要從新編譯github

查閱了下資料,按照以下步驟,並作了些註釋和改動app

1.http://sourceforge.net/projects/lame/files/lame/3.99/ 下載lame的最新版本解壓到一個文件夾裏例如 lame,全路徑以下/Users/8wm/Desktop/lamefrontend

2.下載build的腳本,我這裏使用的是國外一個朋友的分享編輯器

https://github.com/kewlbear/lame-ios-buildui

下載以後獲得lame-build.sh拷貝到文件夾/Users/8wm/Desktop/lamespa

3.用bbedit或者其餘編輯器打開這個腳本,按照註釋修改.net

4.打開Terminals,命令行

輸入

cd /Users/8wm/Desktop/lame

chmod 777 lame-build.sh

sudo -s#

輸入系統密碼

./lame-build.sh

開始編譯,編譯完成以後。生成fat-lame目錄和thin-lame目錄,分別存放合併全部指令集的靜態庫,以及各指令集的靜態庫.

根據所需,copy lame.h和libmp3lame.a文件到project裏,就能夠正常使用了。

能夠使用命令行,查看換個庫支持的指令集。

lipo -info libmp3lame.a

Architectures in the fat file: libmp3lame.a are: armv7 armv7s i386 x86_64 arm64

如下是build的腳本,請注意黃色的字和註釋。

 

#!/bin/sh  
  
make distclean  
  
CONFIGURE_FLAGS="--disable-shared --disable-frontend"  
  
ARCHS="arm64 armv7s x86_64 i386 armv7"  
  
# directories  
# SOURCE是下載lame源碼包,解壓後的目錄,能夠把sh腳本放到這個目錄,source改成""  
SOURCE=""  
# FAT是全部指令集build後,輸出的目錄,全部靜態庫被合併成一個靜態庫  
FAT="fat-lame"  
  
# SCRATCH是下載lame源碼包,解壓後的目錄,必須是絕對路徑  
SCRATCH="/Users/8wm/Desktop/lame"  
# must be an absolute path  
# THIN 各自指令集build後輸出的靜態庫所在的目錄,每一個指令集爲一個靜態庫  
THIN=`pwd`/"thin-lame"  
  
COMPILE="y"  
LIPO="y"  
  
if [ "$*" ]  
then  
    if [ "$*" = "lipo" ]  
    then  
        # skip compile  
        COMPILE=  
    else  
        ARCHS="$*"  
        if [ $# -eq 1 ]  
        then  
            # skip lipo  
            LIPO=  
        fi  
    fi  
fi  
  
if [ "$COMPILE" ]  
then  
    CWD=`pwd`  
    echo "$CWD/$SOURCE........."  
    for ARCH in $ARCHS  
    do  
        echo "building $ARCH..."  
        mkdir -p "$SCRATCH/$ARCH"  
        cd "$SCRATCH/$ARCH"  
  
        if [ "$ARCH" = "i386" -o "$ARCH" = "x86_64" ]  
        then  
            PLATFORM="iPhoneSimulator"  
            if [ "$ARCH" = "x86_64" ]  
            then  
                SIMULATOR="-mios-simulator-version-min=7.0"  
                        HOST=x86_64-apple-darwin  
            else  
                SIMULATOR="-mios-simulator-version-min=5.0"  
                        HOST=i386-apple-darwin  
            fi  
        else  
            PLATFORM="iPhoneOS"  
            SIMULATOR=  
                    HOST=arm-apple-darwin  
        fi  
  
        XCRUN_SDK=`echo $PLATFORM | tr '[:upper:]' '[:lower:]'`  
        CC="xcrun -sdk $XCRUN_SDK clang -arch $ARCH"  
        #AS="$CWD/$SOURCE/extras/gas-preprocessor.pl $CC"  
        CFLAGS="-arch $ARCH $SIMULATOR"  
        CXXFLAGS="$CFLAGS"  
        LDFLAGS="$CFLAGS"  
  
        CC=$CC $CWD/$SOURCE/configure \  
            $CONFIGURE_FLAGS \  
                    --host=$HOST \  
            --prefix="$THIN/$ARCH" \  
                    CC="$CC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS"  
  
        make -j3 install  
        cd $CWD  
    done  
fi  
  
if [ "$LIPO" ]  
then  
    echo "building fat binaries..."  
    mkdir -p $FAT/lib  
    set - $ARCHS  
    CWD=`pwd`  
    cd $THIN/$1/lib  
    for LIB in *.a  
    do  
        cd $CWD  
        lipo -create `find $THIN -name $LIB` -output $FAT/lib/$LIB  
    done  
  
    cd $CWD  
    cp -rf $THIN/$1/include $FAT  
fi
相關文章
相關標籤/搜索