Nicolas Desprès
3/24/2006 7:49:00 AM
Hi there,
I'm having trouble trying to embed Ruby in a C program.
$ cat test.c
#include <ruby.h>
int main()
{
ruby_init();
ruby_script("test");
ruby_init_loadpath();
rb_eval_string("require 'tk'");
return 0;
}
$ gcc -o test test.c -L/opt/ruby-1.8.4/lib -lruby
-I/opt/ruby-1.8.4/lib/ruby/1.8/i686-linux
$ ./test
/opt/ruby-1.8.4/lib/ruby/site_ruby/1.8/i686-linux/tcltklib.so: [BUG]
Segmentation fault
ruby 1.8.4 (2005-12-24) [i686-linux]
zsh: abort ./test
$ ruby -e "require 'tk'"
$
As you can check require 'tk' works fine using ruby -e, but it fails
with the C version. I've check requiring others files such as
thread.rb, pathname.rb, digest.so, readline.so, dl.so, ... and they
all work with both ruby -e and my C program. I don't understand what
I'm doing wrong in my C code.
Any help, would be great,
Cheers,
--
Nicolas Desprès