[英]embed ruby code in C
I know there's severals post about this, but i'm stack 我知道有几个关于此的帖子,但我是堆栈
here's my C code 这是我的C代码
#include </usr/include/ruby-1.9.1/ruby/ruby.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
ruby_init();
rb_eval_string("puts 'hello'");
ruby_finalize();
return 0;
}
i've got the following error when compile it in sublime text 2 我在sublime text 2中编译它时遇到以下错误
In file included from /Users/pierrebaille/Code/Ruby/embedRuby/embedRubyFirst.c:1:
/usr/include/ruby-1.9.1/ruby/ruby.h:1481:24: error: ruby/subst.h: No such file or directory
[Finished in 0.1s with exit code 1]
thanks for your help 谢谢你的帮助
You should not hard-code the full path of a header file like 你不应该硬编码头文件的完整路径,如
#include </usr/include/ruby-1.9.1/ruby/ruby.h>
proper is 适当的是
#include <ruby.h>
and told your gcc to search the header file via CFLAGS and libariy via LD_FLAGS, simply command without makefile could be: 并告诉你的gcc通过CFLAGS和libariy通过LD_FLAGS搜索头文件,简单的命令没有makefile可能是:
gcc -o demo.exe -I/path/to/ruby/headers rubydemo.c -L/path/to/ruby/lib -lruby-libary-name
One of you files you're including in turn includes ruby/subst.h
, , but it appears that ruby
is not in your path, which is why you have this in your code: 你包含的其中一个文件又包含ruby/subst.h
,但似乎ruby
不在你的路径中,这就是为什么你的代码中有这个:
#include </usr/include/ruby-1.9.1/ruby/ruby.h>
Instead of hardcoding paths you should simply add "/some_path/" to your compiler path(s) setting, where some_path
contains the folder ruby
as a child. 您应该只将“/ some_path /”添加到编译器路径设置,而不是硬编码路径,其中some_path
包含文件夹ruby
作为子项。 Now your own include turns into: 现在你自己的包括变成:
#include <ruby/ruby.h>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.