Ruby Gems C扩展示例不工作
我正试图按照这个教程在RubyGems中构建c扩展 我有以下文件: ext/my_malloc/extconf.rb ext/my_malloc/my_malloc.c 但是,我在最后一个命令中遇到以下错误:Ruby Gems C扩展示例不工作,ruby,gem,ruby-c-extension,Ruby,Gem,Ruby C Extension,我正试图按照这个教程在RubyGems中构建c扩展 我有以下文件: ext/my_malloc/extconf.rb ext/my_malloc/my_malloc.c 但是,我在最后一个命令中遇到以下错误: /Users/Daniel/.rbenv/versions/2.1.6/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- my_malloc (LoadE
/Users/Daniel/.rbenv/versions/2.1.6/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- my_malloc (LoadError)
from
/Users/Daniel/.rbenv/versions/2.1.6/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
注意,我使用的是rbenv,我尝试过运行rbenv rehash,现在运行的是版本2.1.6。正确的shell命令是:
ruby -Iext/my_malloc -r my_malloc -e "p MyMalloc.new(5).free"
该代码还有一些其他错误。正确的
rb_raise(rb_eNoMemError, "unable to allocate %ld bytes", requested);
到
因为请求的具有类型size\u t
而不是long
(PRIuSIZE
是非标准的,在“ruby/ruby.h”
中定义)。及
到
要实际定义MyMalloc
类。-Ilib:ext
->-Ilib/ext
,错误仍然会发生谢谢。仅供参考,更改为PRIuSIZE会在makewarning:data参数未被format string[-Wformat extra args]
使用时引发警告。已修复该问题。%
。人物不见了。
/Users/Daniel/.rbenv/versions/2.1.6/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- my_malloc (LoadError)
from
/Users/Daniel/.rbenv/versions/2.1.6/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
ruby -Iext/my_malloc -r my_malloc -e "p MyMalloc.new(5).free"
rb_raise(rb_eNoMemError, "unable to allocate %ld bytes", requested);
rb_raise(rb_eNoMemError, "unable to allocate %" PRIuSIZE " bytes", requested);
cMyMalloc = rb_const_get(rb_cObject, rb_intern("MyMalloc"));
cMyMalloc = rb_define_class("MyMalloc", rb_cObject);