2

I know there's severals post about this, but i'm stack

here's my C code

#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

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

0

2 Answers 2

6

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 -o demo.exe -I/path/to/ruby/headers rubydemo.c -L/path/to/ruby/lib -lruby-libary-name

Sign up to request clarification or add additional context in comments.

2 Comments

thank you, demo.exe? if i am on OSX i should use something else no? like demo.rbo maybe? sorry i'm a beginner. I think i should take time to learn more about gcc...
could be, I am not sure, no have OS-X in hand.
3

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:

#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. Now your own include turns into:

#include <ruby/ruby.h> 

3 Comments

i don't know how to add path to my compiler... but i've moved the ruby 1.9.1 folder into my usr/include folder wich is, i think, in the compiler path. no?
when i just replace my hardcoded include with #include <ruby/ruby.h>
it give me this error: Undefined symbols for architecture x86_64: "_rb_eval_string", referenced from: _main in ccqmMJJ3.o "_ruby_finalize", referenced from: _main in ccqmMJJ3.o "_ruby_init", referenced from: _main in ccqmMJJ3.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status [Finished in 0.5s with exit code 1]

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.