c - 在 C 中运行 Ruby

标签 c ruby linux api ubuntu

我正在尝试在 C 程序中运行一段 Ruby 代码。

我有以下代码:

#include <ruby.h>

int main(int argc, char* argv[])
{
    /* Construct the VM */
    ruby_init();

    /* Ruby goes here */

    /* Destruct the VM */
    return ruby_cleanup(0);
}

但是当我尝试运行该程序时,出现以下错误:

fatal error :ruby.h:没有这样的文件或目录

#include <ruby.h>

我读到需要使用 Ubuntu 中的以下代码告诉编译器所需 header 的包含路径:

pkg-config --cflags --libs ruby-2.5

gcc -I/usr/include/ruby-2.5.0 -I/usr/include/ruby-2.5.0/x86_64-linux -lruby

我已经这样做了,但问题还没有解决。

这是链接:https://silverhammermba.github.io/emberb/embed/

最佳答案

按照 How can I include a needed C library using GCC?中的步骤操作

我不明白两个-l之间的区别,但尝试遵循以下结构。如果我是对的,你的命令将是这样的:

gcc -I/usr/include/ruby-2.5.0 -L/usr/include/ruby-2.5.0/x86_64-linux -lruby

地点:

-I <searchpath to include files>
-L <searchpath to the lib file>
-l <thelibname>

我不知道库是第一个参数还是第二个参数,但你可以检查一下。

关于c - 在 C 中运行 Ruby,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59331345/

相关文章:

linux - ./配置: Permission denied while trying to install python on chromebook

linux - 我如何获得由 grub2 以与发行版无关的方式加载为根设备的 cpio 归档文件制成的 initrd?

python - 如何创建一个日志文件来记录 python 中的每个步骤?

c - 以下程序打印什么?

c - 这个循环是无限的,但它不应该是 - C

c - 如何在 C 上连接到服务器,定义两侧端口

ruby-on-rails - alias_method_chain 是 alias_method 的同义词吗?

html - 帮助在 HTML 中插入 Ruby 脚本

c# - 检查应用程序是否安装在注册表中

ruby - 在 ruby​​ 中使用什么函数来模拟 for