Invoking Ruby 1.9.1 interpreter within C, on OS X gcc

P

Paul Wuersig

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
 
E

Eric Christopherson

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.
 
P

Paul Wuersig

Eric said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,057
Messages
2,570,443
Members
47,113
Latest member
XZJMike318

Latest Threads

Top