Problems with calling ruby from a C program - undefined symbols

Hi,

I am writing a program in C. From this program I need to call into some Ruby
scripts. While for the most part everything works ok, I cannot require/use
the ruby socket library from my scripts if they are called from the C program.

Basically as soon as i try to require socket, I get the following error:
#<LoadError: /usr/local/lib/ruby/1.6/i686-linux/socket.so: undefined symbol:
rb_eSecurityError - /usr/local/lib/ruby/1.6/i686-linux/socket.so>

I am not sure if there is something wrong with the way I am building my C
executable… I searched on the ruby-lang website, but did not find anything
obviously related to my problem.

Have included dumps of the files in question at the end of this email - would
appreciate any help that you can give me…

Cheers,
Martin Hart
martin@zsdfherg.com

Files…

[martin@dorfl test]$ ruby -v
ruby 1.6.6 (2002-01-21) [i686-linux]

[martin@dorfl test]$ cat broken.rb

begin
require "socket"
puts "Everything worked"
rescue Exception => e
p e
end

[martin@dorfl test]$ ruby broken.rb
Everything worked

[martin@dorfl test]$ cat broken.c
#include “ruby.h”

int main()
{
VALUE val;

ruby_init();
ruby_script(“embedded”);
ruby_init_loadpath();
val = rb_require(“broken.rb”);
return 0;
}

[martin@dorfl test]$ cat makefile

makefile for spmod_ruby

CC = gcc
RUBY_INC_PATH=/usr/local/lib/ruby/1.6/i686-linux
CFLAGS = -D_LINUX -fPIC -Wall -g -O -pedantic -lpthread -I$(RUBY_INC_PATH)
RUBY_LIB_PATH = /usr/local/lib/ruby/1.6/i686-linux

all: broken

broken.o: broken.c

broken: broken.o
$(CC) -g broken.o -L$(RUBY_LIB_PATH) -o broken -lruby -ldl -lm -lcrypt

… And finally here is what happens if I run the C program…

[martin@dorfl test]$ ./broken
#<LoadError: /usr/local/lib/ruby/1.6/i686-linux/socket.so: undefined symbol:
rb_eSecurityError - /usr/local/lib/ruby/1.6/i686-linux/socket.so>

You have forgotten the flag -rdynamic

broken: broken.o
        $(CC) -g broken.o -L$(RUBY_LIB_PATH) -o broken -lruby -ldl -lm -lcrypt

           $(CC) -g broken.o -rdynamic -L$(RUBY_LIB_PATH) -o broken -lruby -ldl -lm -lcrypt

Guy Decoux