2012-02-09 18 views
13

LAME (http://lame.sourceforge.net/) là một thư viện được viết bằng ngôn ngữ c. Nó có thể chuyển đổi các tập tin âm thanh PCM sang các tập tin MP3. Tôi sử dụng nó để chuyển đổi các tập tin âm thanh sang các tập tin MP3 trên iPhone. Các tệp âm thanh PCM nguồn được ghi lại bằng micrô.Làm thế nào tôi có thể biên dịch lame thành thư viện tĩnh (.a) cho armv6 và armv7 của iPhone?

Để đưa LAME vào dự án XCode của mình, tôi cần biên dịch LAME thành 3 thư viện tĩnh (.a), cho i386 (IOS Simulator), armv6 và armv7.

Sau nhiều lần tìm kiếm, tôi đã tuân thủ một thư viện tĩnh cho phiên bản i368 (Trình mô phỏng iOS) thành công. Đây là các lệnh:

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

Vấn đề là tôi không thể biên dịch cho armv6 và armv7. Tôi đã thử các lệnh này nhưng nó báo cáo lỗi. Có ai có giải pháp?

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

Lỗi này là:

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 

Khi tôi cài đặt ncurses, Nó báo cáo này:

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

Có ai đó có thể cho tôi một cách để biên dịch LAME vào thư viện tĩnh (. a) cho armv6 và armv7?

Trả lời

13

Bạn đang thiếu một vài bước. Trước hết, bạn không muốn xây dựng giao diện người dùng vì bạn chỉ có thể sử dụng LAME làm thư viện. Bạn cũng phải xây dựng thư viện tĩnh nếu không bạn sẽ không thể xây dựng nó vào dự án của bạn. Về cơ bản, bạn phải thiết lập cây nguồn và biên dịch nó bốn lần, một lần cho các mô phỏng (i686), iPhone (armv6), iPad (armv7) và iPhone 5 (armv7s) sau đó lipo các tập tin .a với nhau thành một thư viện phổ quát. Trình liên kết Xcode sẽ sắp xếp mọi thứ khác cho bạn khi bạn biên dịch phần còn lại của dự án.

Tôi đã sử dụng tập lệnh shell này để tạo tệp libmp3lame.a phổ quát. Lưu ý điều này sử dụng đường dẫn Xcode 4.3 và trình biên dịch 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 

Hãy file libmp3lame.a từ ./build cùng với các tập tin lame.h từ thư mục bao gồm và thả chúng vào dự án Xcode của bạn và bạn phải sẵn sàng để sử dụng què trong cả hai mô phỏng hoặc một thực thiết bị.

+0

Man, câu trả lời của bạn là trình tiết kiệm cuộc sống :))) Cảm ơn rất nhiều! – Anton

+0

@mcrute Tôi đang sử dụng tập lệnh chính xác này ngoại trừ tôi đã thay đổi phiên bản sdk thành 6.0 và tôi nhận được lỗi sau vào cuối: lipo: build/libmp3lame-armv6.a và xây dựng/libmp3lame-armv7.a có cùng kiến ​​trúc (armv7) và không thể nằm trong cùng một tệp kết xuất chất béo – JonathanC

+0

@mcrute cũng lưu ý rằng để hỗ trợ iPhone5, bạn cần phải thêm PLATFORM = "armv7s" build_lame – JonathanC

4

Cảm ơn @mcrute vì câu trả lời tuyệt vời của anh ấy và XCode 5 requirement update Tôi đã cập nhật tập lệnh. Hy vọng nó hữu ích cho người dùng mới.

Chú ý: Đừng quên cập nhật SDK_VERSION dựa trên cài đặt hệ thống của bạn

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

Roozbeh, sau khi chạy tập lệnh, tôi đã gặp phải lỗi này: cấu hình: lỗi: trong '/Users/ivan/Desktop/lame-3.99.5 ': cấu hình: lỗi: C preprocessor"/lib/cpp "kiểm tra lỗi không thành công. Bạn có ý tưởng nào để giải quyết nó không? –

+0

Bạn có thể sử dụng môi trường khác nhau. Tôi đã sử dụng OSX 10.8 vào thời điểm đó. Bạn có biết nó đang ở đâu không? Trong cấu hình hoặc thực hiện? –

+0

Xin chào @Ivan Kozlov, bạn có thể thử thêm "CPP =" $ {DEVELOPER} /Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp "xem câu trả lời của tôi bên dưới. – ZYiOS

7

Đối với Xcode 6.1, iOS SDK 8.1, tôi sử dụng bên dưới kịch bản shell:

Hỗ trợ ARMv7, arm64, i686 và 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 
+0

Tôi gặp lỗi khi tạo tệp xây dựng. dòng 13 của tập lệnh này Bạn có thể vui lòng cung cấp tất cả các bản dựng LAME hay không, nó sẽ rất hữu ích Cảm ơn –

+0

@RahulPatel Bạn đã gặp phải lỗi gì? – ZYiOS

+0

Không tìm thấy một số tệp .sh.Tôi nghĩ có điều gì đó sai với đường dẫn –