[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Embedding Ruby in C

Zach Dennis

12/2/2003 4:15:00 AM


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




1 Answer

Eric Sunshine

12/2/2003 5:10:00 AM

0

On Tue, 2 Dec 2003 13:15:23 +0900, Zach Dennis wrote:
> 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