Embedding Ruby in C

Z

Zach Dennis

I'm trying a very simple example of embedding Ruby in C and I can't get it
to work, nor can i find any documentation on how to get it to work. Here's
what I've got:

#include <ruby.h>

int main(int argc, char *argv[]) {
ruby_init();
rb_eval_string("puts 'hello world'");
ruby_finalize();
return 0;
}


Here is what i get:

Compiling...
out.c
Linking...
out.obj : error LNK2001: unresolved external symbol _ruby_init
out.obj : error LNK2001: unresolved external symbol _ruby_finalize
out.obj : error LNK2001: unresolved external symbol _rb_eval_string
Debug/out.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

out.exe - 4 error(s), 0 warning(s)

Any ideas? Thanks,

Zach
 
E

Eric Sunshine

out.obj : error LNK2001: unresolved external symbol _ruby_init
out.obj : error LNK2001: unresolved external symbol _ruby_finalize
out.obj : error LNK2001: unresolved external symbol _rb_eval_string

Assuming that you are correctly linking against the ruby library, you also
need to ensure that the RUBY_EXTERN macro (1.8.x) is defined properly (or the
EXTERN macro for ruby 1.6.x). Look inside Ruby's define.h file to see if
this macro is being defined properly for your situation. If it is not, then
you may have to ensure manually that it is defined in an appropriate manner.
For instance, you are using Windows, so:

#define RUBY_EXTERN extern __declspec(dllimport)
#include <ruby.h>

-- ES
 

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,141
Messages
2,570,815
Members
47,361
Latest member
RogerDuabe

Latest Threads

Top