# Invoking Ruby 1.9.1 interpreter within C, on OS X gcc

**URL:** <https://www.ruby-forum.com/t/invoking-ruby-1-9-1-interpreter-within-c-on-os-x-gcc/182193>\
**Category:** Ruby\
**Created:** [January 24, 2010, 8:19pm UTC](https://www.ruby-forum.com/t/invoking-ruby-1-9-1-interpreter-within-c-on-os-x-gcc/182193 "2010-01-24T20:19:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pozza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e8cbc/32.png) [@pozza](https://www.ruby-forum.com/u/pozza)\
**Post date:** [January 24, 2010, 8:19pm UTC](https://www.ruby-forum.com/t/invoking-ruby-1-9-1-interpreter-within-c-on-os-x-gcc/182193/1 "2010-01-24T20:19:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pozza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e8cbc/32.png) [@pozza](https://www.ruby-forum.com/u/pozza)\
**Post date:** [January 25, 2010, 1:45am UTC](https://www.ruby-forum.com/t/invoking-ruby-1-9-1-interpreter-within-c-on-os-x-gcc/182193/2 "2010-01-25T01:45:22Z")

</div>

On Sun, Jan 24, 2010 at 1:19 PM, Paul W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

---

<div class="post-metadata">

**Author:** ![pozza](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e8cbc/32.png) [@pozza](https://www.ruby-forum.com/u/pozza)\
**Post date:** [January 25, 2010, 6:36am UTC](https://www.ruby-forum.com/t/invoking-ruby-1-9-1-interpreter-within-c-on-os-x-gcc/182193/3 "2010-01-25T06:36:50Z")

</div>

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.
