3

I'm trying to compile lame mp3 encoder as static library for iOS. I'd like to support all architectures including i686, armv6, armv7, armv7s and arm64. Here is my build script:

#!/bin/bash
DEVELOPER=`xcode-select -print-path`
SDK_VERSION="7.1"
mkdir build
function build_lame()
{
    make distclean
    ./configure \
    CFLAGS="-isysroot ${DEVELOPER}/Platforms/${SDK}.platform/Developer/SDKs/${SDK}${SDK_VERSION}.sdk" \
    CC="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch ${PLATFORM} -miphoneos-version-min=7.0 " \
    --prefix=/Users/mcrute/Desktop/lame \
    --host="arm-apple-darwin9" \
    --disable-shared \
    --enable-static \
    --disable-decoder \
    --disable-frontend

make -j4
cp "libmp3lame/.libs/libmp3lame.a" "build/libmp3lame-${PLATFORM}.a"
}
SDK="iPhoneSimulator"
PLATFORM="i686"
build_lame
SDK="iPhoneOS"
PLATFORM="armv6"
build_lame
PLATFORM="armv7"
build_lame
PLATFORM="armv7s"
build_lame
PLATFORM="arm64"
build_lame
lipo -create build/* -output build/libmp3lame.a

So the error looks like this:

configure: error: in `/Users/ivan/Desktop/lame-3.99.5':
configure: error: C preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details
make: *** No targets specified and no makefile found.  Stop.
cp: libmp3lame/.libs/libmp3lame.a: No such file or directory

Here is my config.log. | tried to remove arm64 from build targets, but script also failed with same error. Google said that I haven't got gcc but I have.. Looking for any suggestion!

Ivan Kozlov
  • 561
  • 2
  • 8
  • 19
  • `/lib/cpp` seems an odd path to me (especially given the path to `clang`) do you know where that value is coming from? Is there a `cpp` binary under `XcodeDefault.xctoolchain` somewhere? Does setting that as the path for `CPP` solve the problem? – Etan Reisner Sep 17 '14 at 13:04
  • I tried to add env CPP=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp. But its still don't work. – Ivan Kozlov Sep 17 '14 at 13:24
  • Is that the right path? You added that to the `configure` invocation? Did the error change at all? – Etan Reisner Sep 17 '14 at 13:31
  • Unfortunately no. I added CPP env var just before executing build script. But nothing happens:( Could you try to build sources from here: http://lame.sourceforge.net with my script? – Ivan Kozlov Sep 17 '14 at 14:32
  • 1
    So you didn't put it on the `configure` line? With the env var route the error didn't change? Did you `export CPP`? Does putting `CPP=....` on the `configure` line change things? I don't have OS X. – Etan Reisner Sep 17 '14 at 14:34
  • The problem was solved by adding CPP="***" inside configure, thanks Etan! – Ivan Kozlov Sep 18 '14 at 13:43
  • Try this script, if will build LAME as a framework valid for all architectures: https://github.com/wuqiong/mp3lame-for-iOS – Rabi Jun 03 '15 at 12:09

2 Answers2

1

The problem was solved by adding CPP="*" variable inside configure function. CPP was missed in my env. Edited build script should looks like this:

#!/bin/bash

DEVELOPER=`xcode-select -print-path`

SDK_VERSION="7.1"

mkdir build

function build_lame()
{
    make distclean

    ./configure \
    CPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \
    CFLAGS="-isysroot ${DEVELOPER}/Platforms/${SDK}.platform/Developer/SDKs/${SDK}${SDK_VERSION}.sdk" \
    CC="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch ${PLATFORM} -miphoneos-version-min=7.0 " \
    --prefix=/Users/ivan/Desktop/lame-3.99.5 \
    --host="arm-apple-darwin9" \
    --disable-shared \
    --enable-static \
    --disable-decoder \
    --disable-frontend

    make -j4
    cp "libmp3lame/.libs/libmp3lame.a" "build/libmp3lame-${PLATFORM}.a"
}

PLATFORM="i686"
SDK="iPhoneSimulator"
build_lame

PLATFORM="armv6"
SDK="iPhoneOS"
build_lame

PLATFORM="armv7"
build_lame

PLATFORM="armv7s"
build_lame

PLATFORM="arm64"
build_lame

lipo -create build/* -output build/libmp3lame.a
Ivan Kozlov
  • 561
  • 2
  • 8
  • 19
0

From comment to answer.

CPP is being set to a very odd value for some reason.

You are manually setting CC on the configure line to a path inside XcodeDefault.

Try setting CPP on the configure call to an appropriate cpp binary inside XcodeDefault as well.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • In my case, a perfectly normal CPP `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp` failed sanity check with Xcode 11.3. Running the same build script in Terminal works fine. What could be wrong? Would you please take a look at https://stackoverflow.com/questions/59350668/c-preprocessor-applications-xcode-app-contents-developer-toolchains-xcodedefau – kakyo Dec 16 '19 at 06:56