Ruby C扩展编译错误:'event'之前的''''

时间:2012-08-03 22:54:23

标签: c ruby compilation ruby-c-extension

我正在尝试使用C扩展来扩展Ruby以添加事件挂钩。

不幸的是,我收到以下错误:

timber.c:7: error: expected ‘)’ before ‘event’
timber.c: In function ‘timber_init_event_hook’:
timber.c:15: error: ‘timber_trap’ undeclared (first use in this function)
timber.c:15: error: (Each undeclared identifier is reported only once
timber.c:15: error: for each function it appears in.)
timber.c: At top level:
timber.c:21: error: expected ‘)’ before ‘event’
make: *** [timber.o] Error 1

我写的代码:

#include <ruby.h>
#include </Users/paulengel/.rvm/src/ruby-1.9.2-p180/node.h> // #include <node.h> raises `error: node.h: No such file or directory`

// Declarations

static void timber_init_event_hook();
static void timber_trap(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass);
VALUE timber_start(VALUE self);
void Init_timber();

// Definitions

static void timber_init_event_hook() {
  #if defined(RB_EVENT_HOOKS_HAVE_CALLBACK_DATA) || defined(RUBY_EVENT_VM)
    rb_add_event_hook(timber_trap, RUBY_EVENT_CALL | RUBY_EVENT_RETURN | RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN, 0);
  #else
    rb_add_event_hook(timber_trap, RUBY_EVENT_CALL | RUBY_EVENT_RETURN | RUBY_EVENT_C_CALL | RUBY_EVENT_C_RETURN);
  #endif
}

static void timber_trap(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass) {
  rb_funcall(rb_mKernel, rb_intern("puts"), 1, rb_str_new2(event));
}

VALUE timber_start(VALUE self) {
  // Do something
}

void Init_timber() {
  VALUE mTimber = rb_define_module("Timber");
  timber_init_event_hook();
  rb_define_singleton_method(mTimber, "start", timber_start, 0);
}

有人可以帮我解决这个问题吗?提前谢谢。

1 个答案:

答案 0 :(得分:1)

编辑:尝试命名除rb_event_t以外的event内容。虽然我几乎肯定它不是C关键字,但你得到的编译错误似乎与这类问题一致。

编辑编辑:显然不是实际问题,但看起来错误就是这两行。