一个很简单的文件,就是programming ruby 上的例子(http://www.ruby-cn.org/book/ProgrammingRuby/ext_ruby.html),如果扩展名是cpp,则出现这样的错误:
error C2664: 'rb_define_method' : cannot convert parameter 3 from
'unsigned long (unsigned long)' to 'unsigned long (__cdecl *)(...)'
None of the functions with this name in scope match the target type
需要改成.c的文件才行。
如果非要用cpp,可以修改如下:
rb_define_method(cTest, "initialize", RUBY_METHOD_FUNC(t_init), 0);
rb_define_method(cTest, "add", RUBY_METHOD_FUNC(t_add), 1);
博客围绕Ruby扩展展开,提到一个来自programming ruby的例子。若文件扩展名是cpp会报错,需改成.c文件。若非要用cpp,可对代码进行修改,如修改rb_define_method函数的调用方式。
1264

被折叠的 条评论
为什么被折叠?



