Mac OS X10.10_xcode6.1_ios8.1环境下,编译lame静态库libmp3lame.a,支持arm64 armv7s x86_64 i38
来源:程序员人生 发布时间:2014-11-19 08:37:33 阅读次数:3991次
最近升级了系统到Mac OS X 10.10 并且更新了XCode6.1和iOS 8.1
之前app用到的libmp3lame.a静态库,也要支持64位的摹拟器(x86_64)和64位的真机(arm64)指令集。需要重新编译
查阅了下资料,依照以下步骤,并做了些注释和改动
1.http://sourceforge.net/projects/lame/files/lame/3.99/ 下载lame的最新版本解压到1个文件夹里例如 lame,全路径以下/Users/8wm/Desktop/lame
2.下载build的脚本,我这里使用的是国外1个朋友的分享
https://github.com/kewlbear/lame-ios-build
下载以后得到lame-build.sh拷贝到文件夹/Users/8wm/Desktop/lame
3.用bbedit或其他编辑器打开这个脚本,依照注释修改
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后,输出的目录,所有静态库被合并成1个静态库
FAT="fat-lame"
# SCRATCH是下载lame源码包,解压后的目录,必须是绝对路径
SCRATCH="/Users/8wm/Desktop/lame"
# must be an absolute path
# THIN 各自指令集build后输出的静态库所在的目录,每一个指令集为1个静态库
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
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠