基于How can I compile lame as static library...?,我在macbook pro上使用此脚本编译了la脚:
mkdir -p build
rm -rf build/* #*/
function build_lame()
{
make distclean
./configure \
CFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/${SDK}.platform/Developer/SDKs/$SDK$SDK_VERSION.sdk" \
CC="/Applications/Xcode.app/Contents/Developer/usr/bin/gcc -arch $PLATFORM -miphoneos-version-min=7.0" \
--prefix="/Users/$USER/Desktop/$PROJECTNAME" \
--host="arm-apple-darwin9" \
--disable-shared \
--enable-static \
--disable-frontend \
make
cp "$PROJECTNAME/.libs/$PROJECTNAME.a" "build/$PROJECTNAME-$PLATFORM.a"
}
PROJECTNAME=libmp3lame
SDK_VERSION=7.0
SDK="iPhoneSimulator"
PLATFORM="i386"
build_lame
SDK="iPhoneOS"
PLATFORM="armv7"
build_lame
SDK="iPhoneOS"
PLATFORM="armv7s"
build_lame
lipo -create build/$PROJECTNAME-* -output build/$PROJECTNAME.a
然后,将生成的
libmp3lame.a
添加到Xcode 5.0.2中的iPhone项目中。为iOS设备构建时,它可以正常工作。构建模拟器时,我的问题开始了。这样做时,出现以下链接器错误:Undefined symbols for architecture i386:
"_init_xrpow_core_sse", referenced from:
_init_xrpow_core_init in libmp3lame.a(quantize.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
为什么会发生此错误,以及如何解决?
这是来自me脚库的
quantize.c
的代码片段:static void
init_xrpow_core_c(gr_info * const cod_info, FLOAT xrpow[576], int upper, FLOAT * sum)
{
// here, the initialization of xrpow is done in normal c code (i've cut that out to keep it small)
}
void
init_xrpow_core_init(lame_internal_flags * const gfc)
{
gfc->init_xrpow_core = init_xrpow_core_c;
#if defined(HAVE_XMMINTRIN_H)
if (gfc->CPU_features.SSE)
gfc->init_xrpow_core = init_xrpow_core_sse;
#endif
#ifndef HAVE_NASM
#ifdef MIN_ARCH_SSE
gfc->init_xrpow_core = init_xrpow_core_sse;
#endif
#endif
}
最佳答案
问题出在--host
的configure
参数中。需要根据要在其上运行Simulator的计算机进行更改。就我而言,这是2009年中的MacBook Pro,运行Mac OS X 10.8.5。uname -a
报告:
Darwin <my computer name>.local 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64
因此,我疯狂地猜测,在运行模拟器的环境下,
--host
的configure
参数需要设置为i686-apple-darwin12.5.0
。猜测是正确的。现在,我的构建脚本如下所示:mkdir -p build
rm -rf build/* #*/
function build_lame()
{
make distclean
./configure \
CFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/${SDK}.platform/Developer/SDKs/$SDK$SDK_VERSION.sdk" \
CC="/Applications/Xcode.app/Contents/Developer/usr/bin/gcc -arch $PLATFORM -miphoneos-version-min=7.0" \
--prefix="/Users/$USER/Desktop/$PROJECTNAME" \
--host="$HOST" \
--disable-shared \
--enable-static \
--disable-frontend \
make
cp "$PROJECTNAME/.libs/$PROJECTNAME.a" "build/$PROJECTNAME-$PLATFORM.a"
}
PROJECTNAME=libmp3lame
SDK_VERSION=7.0
SDK="iPhoneSimulator"
HOST="i686-apple-darwin12.5.0"
PLATFORM="i686"
build_lame
SDK="iPhoneOS"
HOST="arm-apple-darwin9"
PLATFORM="armv7"
build_lame
SDK="iPhoneOS"
HOST="arm-apple-darwin9"
PLATFORM="armv7s"
build_lame
lipo -create build/$PROJECTNAME-* -output build/$PROJECTNAME.a
在Xcode中为Simulator进行构建时,此方法有效。