2018年9月4日 修订
1. lame版本升级至lame3.100
https://sourceforge.net/projects/lame/files/lame/
2. build脚本编译更新, 请仔细阅读文中脚本代码的改动
https://github.com/kewlbear/lame-ios-build
3. 支持bitcode
4. 支持xcode9.4.1
5. 支持模拟器和真机指令集(64位).
编译好的全指令集库下载, fat-lame是all in one, thin-lame是各自指令集的包, 同时包含.h文件.
https://download.csdn.net/download/vieri_ch/10647619
如需自行build, 按照如下步骤进行.
1. http://sourceforge.net/projects/lame/files/lame/ 下载lame的最新版本(3.100)解压到一个文件夹里. 例如lame,
完整路径如下
/Users/maios/Downloads/lame
2.下载build的脚本,https://github.com/kewlbear/lame-ios-build,下载之后得到build-lame.sh, 复制到如下路径.
/Users/maios/Downloads/lame
3. 用bbedit或者ultraedit打开这个脚本,按照注释修改
第8行改为
SOURCE=""
第11行改为
SCRATCH="/Users/maios/Downloads/lame"
4. 打开Terminals, 依次输入如下命令行
cd /Users/maios/Downloads/lame
chmod 755 ./build-lame.sh
sudo sh ./build-lame.sh
输入系统密码, 开始编译
5. 编译完成, 生成fat-lame目录和thin-lame目录,分别存放合并所有指令集的静态库,以及各指令集的静态库.
6. 根据所需,copy lame.h和libmp3lame.a文件到project里,就可以正常使用了。
7. 查看.a文件的指令集。
lipo -info libmp3lame.a
Architectures in the fat file: libmp3lame.a are: armv7 armv7s i386 x86_64 arm64
8. 验证.a文件是否支持bitcode , 依次执行以下命令行
cd /Users/maios/Downloads/lame/thin-lame/arm64/lib/
ar -x libmp3lame.a
解压抽取出lame.o文件
otool -l lame.o | grep bitcode
返回如下结果, 便是表示该.a库支持bitcode
sectname __bitcode
以下是完整的build的脚本,请注意第8行和第11行。
#!/bin/sh
CONFIGURE_FLAGS="--disable-shared --disable-frontend"
ARCHS="arm64 armv7s x86_64 i386 armv7"
# directories
SOURCE=""
FAT="fat-lame"
SCRATCH="/Users/maios/Downloads/lame"
# must be an absolute path
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`
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"
if ! xcodebuild -version | grep "Xcode [1-6]\."
then
CFLAGS="$CFLAGS -fembed-bitcode"
fi
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