如何编译/创建使用 c 的 ruby​​ 扩展?

发布于 2024-09-30 05:22:20 字数 2826 浏览 2 评论 0原文

我想创建一个使用 c 的 ruby​​ 扩展。但是当我用 gcc 编译它时,我收到此错误:

gcc rubyext.c -orubyext -I /usr/local/include/ruby-1.9.1/

In file included from rubyext.c:1:
/usr/local/include/ruby-1.9.1/ruby/ruby.h:25:25: error: ruby/config.h: No such file or directory
In file included from rubyext.c:1:
/usr/local/include/ruby-1.9.1/ruby/ruby.h:107: error: ‘SIZEOF_INT’ undeclared here (not in a function)
/usr/local/include/ruby-1.9.1/ruby/ruby.h:108: error: ‘SIZEOF_LONG’ undeclared here (not in a function)
/usr/local/include/ruby-1.9.1/ruby/ruby.h:112: error: ‘SIZEOF_VOIDP’ undeclared here (not in a function)
In file included from /usr/local/include/ruby-1.9.1/ruby/ruby.h:1326,
                 from rubyext.c:1:
/usr/local/include/ruby-1.9.1/ruby/missing.h:25: error: redefinition of ‘struct timeval’
/usr/local/include/ruby-1.9.1/ruby/missing.h:35: error: redefinition of ‘struct timespec’
In file included from /usr/local/include/ruby-1.9.1/ruby/intern.h:27,
                 from /usr/local/include/ruby-1.9.1/ruby/ruby.h:1327,
                 from rubyext.c:1:
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/include/varargs.h:4:2: error: #error "GCC no longer implements <varargs.h>."
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/include/varargs.h:5:2: error: #error "Revise your code to use <stdarg.h>."
In file included from /usr/local/include/ruby-1.9.1/ruby/intern.h:29,
                 from /usr/local/include/ruby-1.9.1/ruby/ruby.h:1327,
                 from rubyext.c:1:
/usr/local/include/ruby-1.9.1/ruby/st.h:122: error: expected declaration specifiers or ‘...’ before ‘uint32_t’
In file included from /usr/local/include/ruby-1.9.1/ruby/ruby.h:1327,
                 from rubyext.c:1:
/usr/local/include/ruby-1.9.1/ruby/intern.h:508: error: expected declaration specifiers or ‘...’ before ‘rb_pid_t’
/usr/local/include/ruby-1.9.1/ruby/intern.h:526: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rb_fork’
/usr/local/include/ruby-1.9.1/ruby/intern.h:527: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rb_fork_err’
/usr/local/include/ruby-1.9.1/ruby/intern.h:529: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rb_waitpid’
/usr/local/include/ruby-1.9.1/ruby/intern.h:530: error: expected ‘)’ before ‘pid’
/usr/local/include/ruby-1.9.1/ruby/intern.h:531: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rb_spawn’
/usr/local/include/ruby-1.9.1/ruby/intern.h:532: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rb_spawn_err’
/usr/local/include/ruby-1.9.1/ruby/intern.h:534: error: expected ‘)’ before ‘pid’
/usr/local/include/ruby-1.9.1/ruby/intern.h:652: error: expected declaration specifiers or ‘...’ before ‘uint32_t’

我做错了吗?我的 ruby​​ext.c 文件只有一行代码:

#include <ruby.h>

非常感谢任何帮助。

I want to create a ruby extension that uses c. But when I compile it with gcc, I am getting this error:

gcc rubyext.c -orubyext -I /usr/local/include/ruby-1.9.1/

In file included from rubyext.c:1:
/usr/local/include/ruby-1.9.1/ruby/ruby.h:25:25: error: ruby/config.h: No such file or directory
In file included from rubyext.c:1:
/usr/local/include/ruby-1.9.1/ruby/ruby.h:107: error: ‘SIZEOF_INT’ undeclared here (not in a function)
/usr/local/include/ruby-1.9.1/ruby/ruby.h:108: error: ‘SIZEOF_LONG’ undeclared here (not in a function)
/usr/local/include/ruby-1.9.1/ruby/ruby.h:112: error: ‘SIZEOF_VOIDP’ undeclared here (not in a function)
In file included from /usr/local/include/ruby-1.9.1/ruby/ruby.h:1326,
                 from rubyext.c:1:
/usr/local/include/ruby-1.9.1/ruby/missing.h:25: error: redefinition of ‘struct timeval’
/usr/local/include/ruby-1.9.1/ruby/missing.h:35: error: redefinition of ‘struct timespec’
In file included from /usr/local/include/ruby-1.9.1/ruby/intern.h:27,
                 from /usr/local/include/ruby-1.9.1/ruby/ruby.h:1327,
                 from rubyext.c:1:
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/include/varargs.h:4:2: error: #error "GCC no longer implements <varargs.h>."
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/include/varargs.h:5:2: error: #error "Revise your code to use <stdarg.h>."
In file included from /usr/local/include/ruby-1.9.1/ruby/intern.h:29,
                 from /usr/local/include/ruby-1.9.1/ruby/ruby.h:1327,
                 from rubyext.c:1:
/usr/local/include/ruby-1.9.1/ruby/st.h:122: error: expected declaration specifiers or ‘...’ before ‘uint32_t’
In file included from /usr/local/include/ruby-1.9.1/ruby/ruby.h:1327,
                 from rubyext.c:1:
/usr/local/include/ruby-1.9.1/ruby/intern.h:508: error: expected declaration specifiers or ‘...’ before ‘rb_pid_t’
/usr/local/include/ruby-1.9.1/ruby/intern.h:526: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rb_fork’
/usr/local/include/ruby-1.9.1/ruby/intern.h:527: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rb_fork_err’
/usr/local/include/ruby-1.9.1/ruby/intern.h:529: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rb_waitpid’
/usr/local/include/ruby-1.9.1/ruby/intern.h:530: error: expected ‘)’ before ‘pid’
/usr/local/include/ruby-1.9.1/ruby/intern.h:531: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rb_spawn’
/usr/local/include/ruby-1.9.1/ruby/intern.h:532: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘rb_spawn_err’
/usr/local/include/ruby-1.9.1/ruby/intern.h:534: error: expected ‘)’ before ‘pid’
/usr/local/include/ruby-1.9.1/ruby/intern.h:652: error: expected declaration specifiers or ‘...’ before ‘uint32_t’

Did I do it wrong? My rubyext.c file only has one line of code:

#include <ruby.h>

Any help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兮子 2024-10-07 05:22:20

当然,您不能只包含头文件,您必须链接到 Ruby 库。

阅读Pickaxe 的这一章。

也可以随意浏览我在github上的一些repos,我写了很多C扩展。

如果您需要帮助,请在该网站上给我发送消息。

Of course you cannot just include the header files, you must link to the Ruby library.

Read This chapter from the Pickaxe.

Also feel free to browse some of my repos on github, I write a lot of C extensions.

Send me a message on that site if you need help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文