我正在尝试在 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
我已经这样做了,但问题还没有解决。
最佳答案
按照 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/