opencore-amr-iOS 编译支持bitcode的lib文件

泪湿孤枕 提交于 2019-12-03 03:58:38

最近因工作需要使用到opencore-amr-iOS库,进行caf格式与amr格式互转, 但当前的lib是不支持bitcode选项的, 因此我需要将opencore-amr-iOS重新编一个支持bitcode的版本. 

于是先从github中下载对应的源码, 谁知道这个源码已经4年没有更新了, 事已至此只能碰碰运气看能否正常工作. 果不其然, 自动编译的脚本只支持到了XCode6, 在XCode8环境下编译不通过.

没办法只能google看看有没有碰到同样问题的哥们, 还真能找个一个哥们也在做同样的事情, 附上链接:http://www.code4app.com/blog-721976-132.html; 心中一阵窃喜, 我按照他的步骤结果失败了, 报了好多错误. 好在咱不是轻易放弃的人, 有问题一个一个解决呗.

首先碰到的是:

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, 编译通过了.

然后就是解决bitcode的问题了, 根据上面博客中的内容,重要的是在编译选项中增加bitcode相关的开关, 于是乎,在编译选项中增加了但是又报错了:

configure: error: in `/Users/tbwx/test/opencore-amr-iOS':
configure: error: C++ compiler cannot create executables
See `config.log' for more details

查看config.log中的日志:

clang: error: argument to '-V' is missing (expected 1 value)
clang: error: no input files
configure:3469: $? = 1

看来问题出在config这个文件里, 从文件里找到-V的地方,统统删掉,再来一次. 结果还是报错:

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, 运行正常!

附上最终的编译文件:

#!/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




易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!