【发布时间】:2013-06-21 21:57:41
【问题描述】:
我为 Ruby 编写了一个非常简单的 C 扩展。可惜找不到ruby.h。
这里是extconf.rb:
require "mkmf"
$srcs = %w{hypergeometric.c}
$objs = %w{hypergeometric}
create_makefile("hypergeometric")
这是唯一的源文件:
#include <ruby.h> // have also tried #include "ruby.h", same error.
VALUE cHypergeometric;
void Init_hypergeometric() {
cHypergeometric = rb_define_module("Hypergeometric");
}
当我尝试编译它时,我收到以下错误:
../../../../ext/hypergeometric/hypergeometric.c:1:18: error: ruby.h: No such file or directory
Full gist. 请注意,行号已关闭,因为我主要是注释掉代码而不是删除它。
有趣的是,如果我尝试在不清理的情况下再次编译,我会得到一个不同的错误:
ld: warning: ignoring file hypergeometric, file was built for unsupported file format ( 0x67 0x70 0x63 0x68 0x43 0x30 0x31 0x33 0x38 0x4b 0x73 0x92 0x3d 0xf1 0xa5 0x62 ) which is not the architecture being linked (x86_64): hypergeometric
(完整的输出再次包含在上面的要点中。)
也许这是一个线索?
为什么找不到ruby.h?当我编译NMatrix 或the SciRuby rb-gsl fork 时,它们都可以正常工作并且定位ruby.h 没有问题。 (为了记录,我写了 NMatrix、C 扩展和所有的东西——我把这个特定的扩展基于那个人的 extconf.rb。)
【问题讨论】:
-
是否安装了 ruby-dev 包?
-
不是 Ubuntu,所以没有。除非有某种方法可以在 Mac OS X 上安装我不知道的 ruby-dev。但即使是这样,那也没有意义,因为我的其他 Ruby C 扩展编译得很好。
-
看起来它在抱怨
ruby/subst.h,它不能从ruby.h#include。 -
为什么它在两个位置寻找标题?我看到
/System/Library/Frameworks/ruby.framework/Headers/intern.h:409和/Users/jwoods/.rbenv/versions/2.0.0-p195/include/ruby-2.0.0/ruby/ruby.h:1718。也许不相关,但对我来说似乎很奇怪。 -
你忘记了对象扩展,应该是:
$objs = %w{hypergeometric.o}
标签: c ruby extconf.rb mkmf