移植gnu scientific library(gsl)到ios6 xcode4.2

来源:互联网 发布:算法谜题 pdf 百度云 编辑:程序博客网 时间:2024/05/22 01:29

最近需要在ios6上用到gnu scientific library(gsl)库,但无奈目前还没有人一直过(太小众了),只能自己研究一下了。

1.先去下载一个gsl源代码

去这下:

http://www.gnu.org/software/gsl/

2.解压

把压缩文件解压出来,并查看了INSTALL文件中的指导。

Installation Instructions=========================                                                                GSL follows the standard GNU installation procedure.  To compile GSLyou will need an ANSI C-compiler.  After unpacking the distributionthe Makefiles can be prepared using the configure command,                                                                  ./configure                                                                You can then build the library by typing,                                                                  make                                                                Both static and shared versions of the libraries will be compiled bydefault.  Compilation of shared libraries can be turned off byspecifying the `--disable-shared' option to `configure', e.g.                                                                  ./configure --disable-shared

需要先configure,再make.嗯,gnu的一贯风格。

3.configure参数

默认的configure会直接编译i686下的库,而ios是需要arm7的库,你懂的。所以不能使用默认的参数。

我们要做的就是指定下面的参数:

  1. 编译器,采用ios6的编译器,可以编译arm7结构的库

  2. 连接器,也用ios6的

  3. 库目录,arm自己的标准C++库

  4. 头文件目录,arm自己的C++头文件目录

  5. 目标机器架构,这里选arm

好在a/b/c都在Xcode中包含了。

我的Xcode安装目录在:/Applications/Xcode.app/Contents/Developer/

a.编译器指定为:CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2

b.链接器:LD=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld

c.库目录指定为:LIBS="-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/system"

d.头文件:CFLAGS=-I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/include

e.目标机器架构,--host=arm

所以有下面的configure命令

./configure CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 CFLAGS=-I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/include LIBS="-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/system" LD=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ld --host=arm

4.make

开始make把。

很快就会有错误:

ldfrexp.c:63: error: 'gsl_finite' is unavailable (declared at ../gsl/gsl_sys.h:45)ldfrexp.c:88: error: 'gsl_finite' is unavailable (declared at ../gsl/gsl_sys.h:45)

别怕。arm的函数有一些不同,需要修改一下:

在文件gsl/gsl_math.h 

#define GSL_IS_REAL(x) (gsl_finite(x))(第119行)下面插入

#define gsl_finite(x) (isfinite(x))

然后保存。

再make即可。


然后就会在.libs/目录下生成libgsl.a文件了。



原创粉丝点击