14

LAME(http://lame.sourceforge.net/) is a library written in c language. It can convert PCM sound files to MP3 files. I use it to convert sound files to MP3 files on iPhone. The source PCM sound files is recorded by microphone.

In order to include the LAME into my XCode Project, I need to compile the LAME to 3 static libraries(.a), for i386(IOS Simulator), armv6 and armv7.

After a lot of search, I have complied a static library for i368 version(iOS Simulator) successfully. Here is commands:

./configure \
    CFLAGS="-isysroot  /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk" \
    CC="/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386" \
    --prefix=/Volumes/Data/test/i386 \
    --host="arm-apple-darwin9"

make && make install

The problem is I can not compile for armv6 and armv7. I have tried this commands but it report an error. Is there anybody have solutions?

./configure \
    CFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk" \
    CC="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6" \
    --prefix=/Volumes/Data/test/arm6 \
    --host="arm-apple-darwin9"

make && make install

The error is:

console.c:25:21: error: curses.h: No such file or directory
console.c:27:20: error: term.h: No such file or directory
console.c: In function ‘get_termcap_string’:
console.c:92: warning: implicit declaration of function ‘tgetstr’
console.c:92: warning: assignment makes pointer from integer without a cast
console.c: In function ‘get_termcap_number’:
console.c:102: warning: implicit declaration of function ‘tgetnum’
console.c: In function ‘apply_termcap_settings’:
console.c:115: warning: implicit declaration of function ‘tgetent’
make[2]: *** [console.o] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

When I install ncurses, It reported this:

../curses.h:60:25: error: ncurses_dll.h: No such file or directory
In file included from console.c:25:
../curses.h:250: warning: return type defaults to ‘int’
../curses.h: In function ‘NCURSES_EXPORT_VAR’:
../curses.h:250: error: expected declaration specifiers before ‘acs_map’
../curses.h:340: error: storage class specified for parameter ‘SCREEN’
../curses.h:341: error: storage class specified for parameter ‘WINDOW’
../curses.h:343: error: storage class specified for parameter ‘attr_t’
../curses.h:388: warning: empty declaration
../curses.h:401: error: expected specifier-qualifier-list before ‘attr_t’
../curses.h:443: warning: empty declaration
../curses.h:542: error: storage class specified for parameter ‘NCURSES_OUTC’
../curses.h:551: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘addch’
../curses.h:552: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘addchnstr’
../curses.h:553: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘addchstr’
../curses.h:554: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘addnstr’

Is there somebody can give me a way to compile LAME to static library(.a) for the armv6 and armv7?

rexshi
  • 179
  • 1
  • 7

3 Answers3

14

You're missing a few steps. First of all you don't want to build the frontend at all since you'll only be able to use LAME as a library anyhow. You also have to build the library statically otherwise you won't be able to build it into your project.

Basically, you have to setup the source tree and compile it four times, once for the simulator (i686), iPhone (armv6), iPad (armv7) and iPhone 5 (armv7s) then lipo the .a files together into a universal library. The Xcode linker will sort everything else out for you when you compile the rest of your project.

I used this shell script to build a universal libmp3lame.a file. Note this uses Xcode 4.3 paths and iOS 5.1 compilers.

#!/bin/bash

SDK_VERSION="5.1"

mkdir 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/Platforms/${SDK}.platform/Developer/usr/bin/gcc -arch ${PLATFORM}" \
        --prefix=/Users/mcrute/Desktop/lame \
        --host="arm-apple-darwin9" \
        --disable-shared \
        --enable-static \
        --disable-decoder \
        --disable-frontend

    make
    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

lipo -create build/* -output build/libmp3lame.a

Take the libmp3lame.a file from ./build along with the lame.h file from the include directory and drop them in your Xcode project and you should be ready to use lame in either the simulator or a real device.

mcrute
  • 1,592
  • 1
  • 16
  • 27
  • Man, your answer is a life saver :))) Thanks a lot! – Anton Jun 05 '12 at 20:36
  • @mcrute I am using this exact script except I have changed the sdk version to 6.0 and I get the following error at the very end: lipo: build/libmp3lame-armv6.a and build/libmp3lame-armv7.a have the same architectures (armv7) and can't be in the same fat output file – JonathanC Nov 07 '12 at 01:10
  • @mcrute also note that to support iPhone5 you need to add PLATFORM="armv7s" build_lame – JonathanC Nov 09 '12 at 19:35
  • @JonathanC I haven't tested this under SDK 6.0. My guess would be Apple changed something with the way v6 and v7 binaries are compiled but off the top of my head I'm not sure. – mcrute Nov 19 '12 at 14:05
  • I opted to stop supporting armv6 because I don't support the armv6 devices anyway. ARMv6 = iPhone 2G/3G, iPod 1G/2G – JonathanC Nov 28 '12 at 18:35
  • @Anton Is there any chance, if can you share static library .a file you created ? – Janak Nirmal Feb 12 '13 at 14:03
  • @mcrute Hi! Thanks for your script, that worked like a chame. I'm trying to use Lame, with this code: http://www.tekritisoftware.com/convert-caf-to-mp3-in-iOS that seems OK, I have a crash on line read = fread(pcm_buffer, 2*sizeof(short int), PCM_SIZE, pcm); any ideas about how to solve it? Thank you! – neowinston May 14 '13 at 19:15
7

For Xcode 6.1, iOS SDK 8.1, I use below shell script:

Support armv7, arm64, i686 and x86_64

#!/bin/bash

DEVELOPER=`xcode-select -print-path`

SDK_VERSION="8.1"

LAMEDIR="/Users/zuyuanzhou/Downloads/lame-3.99.5"

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 " \
CPP="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \
--prefix="$LAMEDIR" \
--host="$HOST" \
--disable-shared \
--enable-static \
--disable-decoder \
--disable-frontend

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


PLATFORM="i686"
SDK="iPhoneSimulator"
HOST="i686-apple-darwin14.1.0"
build_lame

PLATFORM="x86_64"
build_lame

PLATFORM="armv7"
SDK="iPhoneOS"
HOST="arm-apple-darwin9"
build_lame

PLATFORM="arm64"
build_lame

lipo -create build/* -output build/libmp3lame.a
ZYiOS
  • 5,204
  • 3
  • 39
  • 45
  • I am getting error while creating build file. Getting error on line 13 of this script. Can you please provide all LAME builds then it would be helpful. Thanks – Rahul Patel Dec 20 '14 at 17:43
  • Some .sh files are not found. I think something is wrong with path. – Rahul Patel Dec 22 '14 at 05:52
4

Thanks @mcrute for his great answer, and XCode 5 requirement update I have updated script. Hope it useful for new users.

NOTE: Don't forget to update SDK_VERSION based on your system installation

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

PLATFORM="i686"
SDK="iPhoneSimulator"
build_lame

PLATFORM="armv6"
SDK="iPhoneOS"
build_lame

PLATFORM="armv7"
build_lame

PLATFORM="armv7s"
build_lame

lipo -create build/* -output build/libmp3lame.a
Community
  • 1
  • 1
Roozbeh Zabihollahi
  • 7,207
  • 45
  • 39
  • 1
    Roozbeh, after running script I've got this error: configure: error: in `/Users/ivan/Desktop/lame-3.99.5': configure: error: C preprocessor "/lib/cpp" fails sanity check . Have you got any ideas how to solve it? – Ivan Kozlov Sep 17 '14 at 11:49
  • You probably using different environment. I was using OSX 10.8 at the time. Do you know where it is failing? In configure or make ? – Roozbeh Zabihollahi Sep 17 '14 at 19:20
  • Hi @Ivan Kozlov, you can try to add "CPP="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" see my answer below. – ZYiOS Dec 02 '14 at 08:25