gpt4 book ai didi

c - 将 Ruby 解释器链接到 C 程序中

转载 作者:行者123 更新时间:2023-11-30 14:32:48 25 4
gpt4 key购买 nike

我正在尝试将 Ruby 解释器包含在 C 程序中。我一直使用此链接作为指南:https://silverhammermba.github.io/emberb/embed/#startup-teardown .

我在 C 中有以下代码:

#include <ruby.h>

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

// puts "hola"
/* Ruby goes here */

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

问题是当我尝试编译代码时,我收到以下消息:

ruby_init 的引用未定义

ruby_cleanup 的引用未定义

最佳答案

您需要链接到libruby ,如链接中所述:

Embedding Ruby requires one header ruby.h, which includes a platform-specific header ruby/config.h. You will probably need to tell your compiler about the include paths for these headers. You will also need to link with the Ruby lib. On my machine, my minimal compiler options are

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

Though, if available, you should really use pkg-config to get the appropriate options for your distribution:

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

将这两者结合起来,你会得到 gcc $(pkg-config --cflags --libs ruby-2.5) <files> <libs> .

关于c - 将 Ruby 解释器链接到 C 程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59674947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com