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

最近需要在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 GSL
you will need an ANSI C-compiler.  After unpacking the distribution
the 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 by
default.  Compilation of shared libraries can be turned off by
specifying 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文件了。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值