首页 > 代码库 > Mac OS X10.10_xcode6.1_ios8.1环境下,编译lame静态库libmp3lame.a,支持arm64 armv7s x86_64 i386 armv7指令集

Mac OS X10.10_xcode6.1_ios8.1环境下,编译lame静态库libmp3lame.a,支持arm64 armv7s x86_64 i386 armv7指令集

最近升级了系统到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的最新版本解压到一个文件夹里例如 lame,全路径如下/Users/8wm/Desktop/lame


2.下载build的脚本,我这里使用的是国外一个朋友的分享

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后,输出的目录,所有静态库被合并成一个静态库
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

Mac OS X10.10_xcode6.1_ios8.1环境下,编译lame静态库libmp3lame.a,支持arm64 armv7s x86_64 i386 armv7指令集