我如何编译lame作为iPhone的armv6和armv7的静态库(.a)?

时间:2012-02-09 07:39:56

标签: iphone static mp3 lame

LAME(http://lame.sourceforge.net/)是一个用c语言编写的库。它可以将PCM声音文件转换为MP3文件。我用它将声音文件转换为iPhone上的MP3文件。源PCM声音文件由麦克风录制。

为了将LAME包含到我的XCode项目中,我需要将LAME编译为3个静态库(.a),i386(IOS模拟器),armv6和armv7。

经过大量搜索,我成功地为i368版本(iOS模拟器)编写了一个静态库。这是命令:

./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

问题是我无法编译armv6和armv7。我试过这个命令,但报告错误。有人有解决方案吗?

./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

错误是:

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

当我安装ncurses时,它报告了这个:

../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’

有人可以给我一种方法将LAME编译为armv6和armv7的静态库(.a)吗?

3 个答案:

答案 0 :(得分:13)

你错过了几步。首先,你根本不想构建前端,因为无论如何你只能使用LAME作为库。您还必须静态构建库,否则您将无法将其构建到项目中。

基本上,您必须设置源树并对其进行四次编译,一次用于模拟器(i686),iPhone(armv6),iPad(armv7)和iPhone 5(armv7s),然后将.a文件合并为一个通用图书馆。在编译项目的其余部分时,Xcode链接器将为您排序其他所有内容。

我使用这个shell脚本来构建一个通用的libmp3lame.a文件。请注意,这使用Xcode 4.3路径和iOS 5.1编译器。

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

将./build中的libmp3lame.a文件与include目录中的lame.h文件一起放入Xcode项目中,您应该准备好在模拟器或真实设备中使用lame。

答案 1 :(得分:7)

对于Xcode 6.1,iOS SDK 8.1,我使用下面的shell脚本:

支持armv7,arm64,i686和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

答案 2 :(得分:4)

感谢@mcrute的出色回答,XCode 5 requirement update我更新了脚本。希望它对新用户有用。

注意:不要忘记根据系统安装更新SDK_VERSION

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