我正在尝试在Ruby的C API中创建一个模块。这是我的代码:
#include <ruby.h>
VALUE TopModule;
VALUE SubModule;
rb_define_module("TopModule");
VALUE ruby_hello_world(VALUE self, VALUE n)
{
return Qnil;
}
void Init_hello_world(void){
rb_define_global_function("ruby_hello_world", ruby_hello_world, 1);
}
当我使用rake编译器编译代码时,它将在rb_define_module中引发错误。错误看起来像这样:
C:\_mks\RubyTool>rake compile
cd tmp/x64-mingw32/hello_world/2.6.1
C:/Ruby/bin/ruby.exe -I. ../../../../ext/hello_world/extconf.rb
cd -
cd tmp/x64-mingw32/hello_world/2.6.1
C:\Ruby\msys64\mingw64\bin\mingw32-make.exe
compiling ../../../../ext/hello_world/hello_world.c
../../../../ext/hello_world/hello_world.c:6:18: error: expected declaration specifiers or '...' before string constant
rb_define_module("TopModule");
^~~~~~~~~~~
mingw32-make: *** [Makefile:244: hello_world.o] Error 1
rake aborted!
Command failed with status (2): [C:\Ruby\msys64\mingw64\bin\mingw32-make.ex...]
知道我缺少什么吗?