Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Gems C扩展示例不工作_Ruby_Gem_Ruby C Extension - Fatal编程技术网

Ruby Gems 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

我正试图按照这个教程在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 (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会在make
warning: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);