【问题标题】:How can I compile lame as static library(.a) for armv6 and armv7 of iPhone?如何将 lame 编译为 iPhone 的 armv6 和 armv7 的静态库(.a)?
【发布时间】:2012-03-01 16:47:09
【问题描述】:

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)的方法?

【问题讨论】:

    标签: iphone static mp3 lame


    【解决方案1】:

    您缺少几个步骤。首先,您根本不想构建前端,因为无论如何您只能将 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。

    【讨论】:

    • 伙计,你的回答是救命稻草 :))) 非常感谢!
    • @mcrute 我正在使用这个确切的脚本,除了我已将 sdk 版本更改为 6.0 并且最后出现以下错误:lipo: build/libmp3lame-armv6.a 和 build/libmp3lame- armv7.a 具有相同的架构(armv7),不能在同一个胖输出文件中
    • @mcrute 还要注意,要支持 iPhone5,您需要添加 PLATFORM="armv7s" build_lame
    • @JonathanC 我没有在 SDK 6.0 下测试过这个。我的猜测是 Apple 改变了 v6 和 v7 二进制文件的编译方式,但我不确定。
    • 我选择停止支持 armv6,因为我不支持 armv6 设备。 ARMv6 = iPhone 2G/3G、iPod 1G/2G
    【解决方案2】:

    对于 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
    

    【讨论】:

    • 创建构建文件时出现错误。在此脚本的第 13 行出现错误。您能否提供所有 LAME 版本,那么它会有所帮助。谢谢
    • 找不到一些 .sh 文件。我认为路径有问题。
    【解决方案3】:

    感谢@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
    

    【讨论】:

    • Roozbeh,在运行脚本后我得到了这个错误:configure: error: in `/Users/ivan/Desktop/lame-3.99.5': configure: error: C preprocessor "/lib/ cpp”未通过完整性检查。你有什么解决办法吗?
    • 您可能使用不同的环境。我当时使用的是 OSX 10.8。你知道它在哪里失败吗?在配置或制作中?
    • 嗨@Ivan Kozlov,您可以尝试添加“CPP="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp”,请参阅下面的答案。
    猜你喜欢
    • 2011-02-17
    • 2023-04-01
    • 2012-01-23
    • 1970-01-01
    • 2012-03-24
    • 2012-01-15
    • 2012-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多