Question

Based on How can I compile lame as static library...?, I've compiled lame using this script on a macbook pro:

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

I then added the resulting libmp3lame.a to an iPhone project in Xcode 5.0.2. When building for an iOS device, it works fine. My problem starts when building for the simulator. When doing this, I get the following linker error:

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)

Why does this error occur and how to solve it?

Here is a code snippet from quantize.c from the lame library:

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
}
Was it helpful?

Solution

The problem was in the --host parameter to configure. It needs to be changed depending on the machine on which you want to run the Simulator. In my case, this is a MacBook Pro from mid 2009, running Mac OS X 10.8.5.

uname -a reports:

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

So I wildly guessed that the --host parameter for configure for this environment, in which the Simulator runs, needs to be set to i686-apple-darwin12.5.0. The guess was right. My build script now looks like this:

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

This works when building for Simulator in Xcode.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top