In article <20040528130908.GD807 / velka.phys.uoa.gr>, Elias Athanasopoulos wrote:
>Hello!
>
>I have a segfault when I use rb_eval_string() through a shared
>library.
>
>elathan@velka:~/TRuby/tmp> ruby -v
>ruby 1.9.0 (2004-05-25) [i686-linux]
>elathan@velka:~/TRuby/tmp> cat bug.c 
>#include "ruby.h"
>
>int doit(void)
>{
>    rb_eval_string("puts");
>}
>    
>elathan@velka:~/TRuby/tmp> gcc bug.c -shared -o libbug.so  \
>-I/usr/local/lib/ruby/1.9/i686-linux/ -L/usr/local/include \
>-lruby-static -ldl -lcrypt -lm
>
>elathan@velka:~/TRuby/tmp> cat runit.c 
>int main(void)
>{
>    doit();
>}
>elathan@velka:~/TRuby/tmp> gcc runit.c -lbug -L. -o runit                       
>elathan@velka:~/TRuby/tmp> ./runit 
>Segmentation fault

(I'm on the newsgroup, perhaps this has already been answered on the mailing
list.)

Before calling any other Ruby functions, try:

        #ifdef _WIN32
            NtInitialize(&argc, &argv);
        #endif
        #if defined(__MACOS__) && defined(__MWERKS__)
            argc = ccommand(&argv);
        #endif
        
        ruby_init();

You might be able to get away with just using ruby_init(), but e.g.
NtInitialize calls the win32 function StartSockets() to "Initialize
Winsock".