Invoking Ruby 1.9.1 interpreter within C, on OS X gcc

As part of a project, I’m trying to set up a system that can run Ruby
scripts (with C functionality) from C. I did this rather easily on 1.8.7
Ruby, but this version is built into my version of SnowLeopard, so it’s
as simple as a #include. I built 1.9.1 from source and installed it to
/usr/local, but I’m having difficulties including everything I need
while compiling the C code that should set up and run the interpreter.

Here’s test.c:
#include <stdlib.h>
#include “ruby.h”

int main(int argc, char **argv) {
ruby_sysinit(&argc, &argv);
{
RUBY_INIT_STACK;
ruby_init();
return ruby_run_node(ruby_options(argc, argv));
}
}

Here’s how I’m trying to compile it:
gcc -I/usr/local/include/ruby-1.9.1/ruby test.c

It complains about undefined symbols for all the ruby calls. I think I’m
missing a pointer to the necessary libraries, but I’m not sure which
directory to point to.

Documentation seems scant for this (obviously rare) usage: my basis for
the 1.8.7 interpreter embedding was an example, which I cannot find for
the equivalent 1.9.1 case. Any help or advice would be greatly
appreciated.

Thanks,
Paul

On Sun, Jan 24, 2010 at 1:19 PM, Paul W. [email protected]
wrote:

Here’s how I’m trying to compile it:
gcc -I/usr/local/include/ruby-1.9.1/ruby test.c

It complains about undefined symbols for all the ruby calls. I think I’m
missing a pointer to the necessary libraries, but I’m not sure which
directory to point to.

You might have success passing -L/usr/local/lib -lruby (or
-lruby-static) on the gcc command line.

Eric C. wrote:

You might have success passing -L/usr/local/lib -lruby (or
-lruby-static) on the gcc command line.

Awesome - I knew I was missing something basic in the gcc call. For the
record, I tried -L/usr/local/lib, but it didn’t change the error in the
absence of the -lruby. Oddly enough, using both those options makes gcc
complain about LESS missing symbols (_ruby_sysinit and _ruby_run_node
only). Not sure why that is. But -lruby-static works great!

Thanks for the help, Eric.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs