speex编译静态库for iOS

来源:互联网 发布:office of mac免费版本 编辑:程序博客网 时间:2024/06/01 09:10

前言

此文转载:
经过1天多的不断尝试和查资料终于完成了speex的静态库编译,关于什么是speex我就不做介绍了,这里有中文比较详细的介绍http://blog.csdn.net/zsjum/article/details/7482331,编译过程遇到了不少问题和困难。
中文资料基本没有,英文资料也没发现什么,所以写下我的经验,给大家一些提醒少走一些弯路,下面我给大家提醒下需要注意的和我理解的关于speex编译的一些东东。
首先speex的编译是建立在ogg,什么是ogg这个我也不做介绍了,作为IT民工度娘谷哥都是我们的老师。所以我们首先要下载ogg对它进行编译,ogg下载地址http://www.xiph.org/downloads/。
speex的下载地址http://www.speex.org
下载好了对于新手来说首先我们应该在什么地方编译,这个问题其实我开始也有疑惑,但想一想除了终端貌似没有什么地方可以编译了,对打开你的终端。
我先把编译的内容发发出来再做具体介绍
把下面的命令在终端执行
(注意不能直接复制过去,这是我的执行路径,而且可能会有中英文字符串的问题(我当时就遇到这个问题),所以你需要改,具体介绍后面说明)编译ogg

1. compile ogg for i386 (simulator)

./configure -prefix=/Users/share02/Desktop/libogg/i386 -host=i386-apple-darwin -build=x86_64-apple-darwin11.4.0 CC=”/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2 -std=c99 -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/”
(在执行的时候如果你的终端提示你不能执行,你可以在前面加一bash然后空格再跟这句命令,其实你可以关机然后重启就能执行了,我也不知道什么问题,有了解的可以留言大家一起学习与进步)
make
(如果你执行make命令是,终端提示没有make这个命令,那么你需要做以下的一步)打开你的xcode,然后
这里写图片描述
这里写图片描述
点击安装你的Downloads下面的Command Line Tools工具,然后就可以了执行make和make install命令了,如果还提示你可以退出然后重新打开你的终端再运行make命令。

make install
(在make install执行完成后,在/Users/share02/Desktop/libogg/这个路径下面会生成i386的文件夹,在i386下面生成了libogg.a这个文件,这就是i386环境用的ogg静态库)

(如果这个时候你的环境被你打乱,没有按照顺序成功执行,你可以在这里执行 make distclean,不然你到后面整合静态库的时候可能会报都是i386的同一个静态库没法整合的错)(我当时就遇到这个问题很蛋疼感觉什么都是对的就是为什么编译成同一个东西了)

2. compile ogg for armv6

./configure -prefix=/Users/share02/Desktop/libogg/armv6 -host=armv6-apple-darwin -build=x86_64-apple-darwin11.4.0 CC=”/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2 -std=c99 -arch armv6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/”

make
make install
(make distclean)

3. compile ogg for armv7

./configure -prefix=/Users/share02/Desktop/libogg/armv7 -host=armv7-apple-darwin -build=x86_64-apple-darwin11.4.0 CC=”/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2 -std=c99 -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/”

make
make install
(make distclean)
编译speex

4. compile speex for i386(simulator)

./configure -prefix=/Users/share02/Desktop/speex-1.2rc1/i386 -host=i386-apple-darwin -disable-shared -enable-static -disable-oggtest -enable-fixed-point -disable-float-api -build=x86_64-apple-darwin11.4.0 -with-ogg=/Users/share02/Desktop/libogg/i386 CC=”/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2 -std=c99 -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/”

make
make install
(make distclean)

5. compile speex for armv6

./configure -prefix=/Users/share02/Desktop/speex-1.2rc1/armv6 -host=armv6-apple-darwin -disable-shared -enable-static -disable-oggtest -enable-fixed-point -disable-float-api -build=x86_64-apple-darwin11.4.0 -with-ogg=/Users/share02/Desktop/libogg/armv6 CC=”/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2 -std=c99 -arch armv6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/”

make
make install
(make distclean)

6. compile speex for armv7

./configure -prefix=/Users/share02/Desktop/speex-1.2rc1/armv7 -host=armv7-apple-darwin -disable-shared -enable-static -disable-oggtest -enable-fixed-point -disable-float-api -build=x86_64-apple-darwin11.4.0 -with-ogg=/Users/share02/Desktop/libogg/armv7 CC=”/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2 -std=c99 -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/”

make
make install
(make distclean)
把上门编译所生成的i386,armv6,armv7的libogg.a整合成一个整体的(意思是3个环境都可以用的)
speex同理

7. combine ogg for ios

lipo -create i386/lib/libogg.a armv6/lib/libogg.a armv7/lib/libogg.a -output libogg.a

8. combine speex for ios

lipo -create i386/lib/libspeex.a armv6/lib/libspeex.a armv7/lib/libspeex.a -output libspeex.a

9. combine speexdsp for iOS

lipo -create i386/lib/libspeexdsp.a armv6/lib/libspeexdsp.a armv7/lib/libspeexdsp.a -output libspeexdsp.a

(特别注意第9步,因为在网上没有任何地方说要编译第9步的,曾经我也没执行这步,后面用到编码函数时候很多报这样的错:Undefined symbols for architecture i386:

“_speex_preprocess_state_init”, referenced from:
-[SpeexEncoder initWithMode:] in SpeexEncoder.o 意思是没有定义没有找到这个函数体,经过几个小时的反复检查还是没有发现什么地方不对,怀疑过库没编译完整,怀疑过路径,怀疑过还差东西以及自己的环境等等,整得很蛋疼,后来google上终于找到一个国外linux论坛上有人问这个问题说到是没有编译speexdsp,speexdsp是扩展的库,后来想办法编译这个东西到处找,没找到,结果无意在编译好的speex中的i386文件下发现已经编译好了speexdsp,加入工程ok没问题了,所以才有第9步把dsp整合成一个静态库,加入工程,呵呵不容易啊坑爹啊)

(注意上面2句执行的时候一定要cd到各自的目录下面去执行,同时提醒记得ogg编译完后编译speex记得换目录,别粗心大意。执行完上面2句整合过后我们就能够在ogg和speex目录下面找到我们所需要libogg.a和libspeex.a静态库)

把上门编译所生成的i386,armv6,armv7的libogg.a整合成一个整体的(意思是3个环境都可以用的)
speex同理,首先我们要注意的是,一次性顺序编译

接下来就是以ogg编译i386为例子对于编译语句的具体分析和说明,虽然不大了解具体意思说的不对请指教,
首先我们应该把下载下来的ogg和speex放在一个路径相对方便的地方,我是放在桌面即Desktop,我们要执行就要cd到ogg或者speex的目录下,这样才能执行configure命令 ,

-prefix后面/Users/share02/Desktop/libogg/i386是编译成功后生成i386文件以及静态库的路径,最好放在你下载的ogg文件下,方便后面整合的时候路径简单。

-host后面是所跟的参数i386-apple-darwin -build=x86_64-apple-darwin11.4.0不需要更改。
CC后面跟的是你xcode,的i386的gcc编译器路径,这个需要根据你自己的xcode的路径来决定,具体咋个看呢,右击你的xcode,在finder中显示,然后
这里写图片描述
然后就可以根据/Contents/Developer/usr/llvm-gcc-4.2/bin/llvm-gcc-4.2 这个路径去看看是不是你的i386的gcc在这个路径下,如果不是请对照你的路径进行更改路径,这里做点小补充,因为我对爱图腾博客所指出的路径进行了一些小改变,其实我是执行了实际路径
(爱图腾博客路径是./configure -prefix=/Users/Rainbow/ogg/i386 –host=i386-apple-darwin –build=x86_64-apple-darwin10.8.0 CC=”/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -std=c99 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/”)。

-isysroot后面跟的是你的iPhoneSimulator或者iPhoneOS的sdk路径,和上面同理写你自己的路径,这个路径和上面差不多。
(最后注意的是字符问题,全是英文,每个参考之间有个空格-prefix,-build, CC, -isysroot这几个前面都有空格,还有提醒就是,如果你的xcode在应用程序里面,这个时候你要在终端查看你的xcode路径,如果你的mac os 语言是中文你就不知道他的路径名字,其实在终端里面cd /然后ls就可以看到Applications这个目录,所有应用程序都在这个目录下,还有注意xcode里面的路径注意是”/Applications/Xcode.app/Contents而不是xcode)。
在编译armv6, armv7的时候你需要注意的是,它们的gcc路径不和i386的相同,注意看我的路径参考,然后根据自己的路径去编译。

好终于写完了,希望对大家有用!

0 0
原创粉丝点击