Loading Native Extensions in embedded Ruby 2.0

Hi everyone, so I have this problem. I am making a 2D game engine which
uses embedded ruby for scripting. So far I’ve successfully embedded it
and it works normally, but when I try to load a native extension into
it, it segfaults and crashes. I’ve tried everything but I don’t know how
to fix this. Any ideas?

I am using static-linked-library version of ruby 2.0. It’s built using
MS Visual C++ 2012. For game rendering I am using Allegro Game library.

Ruby interpreter is fully initialized using this code:

ruby_sysinit(&argc, &argv);


rb_load_protect(rb_str_new_cstr(“boot.rb”, 1, &error);

if (error)
VALUE lasterr = rb_obj_as_string(rb_gv_get(“$!”));
VALUE klass = rb_class_path(CLASS_OF(rb_gv_get(“$!”)));

printf_s(RAGE_RB_SCRIPT_ERROR, StringValueCStr(klass),


I also note that everything else is functioning normally just when I try
to do require “dl” (dl.so extension which was build with static version
of ruby libary 2.0) it segfaults. I’ve tried normal version also. It
needs a dll to be in the working directory and once I put it there it
segfaults the same.
Normally using require (ex.: require “script.rb”) works without

Am I missing some include file? Do I need to compile the library in
another way? Note that I’ve compiled both ruby-static-library 2.0 and my
game engine with -MT (which means static linking of MSVCRT and LIBCMT)
flag and with /NODEFAULTLIB:MSVCRT (since MSVCRT and LIBCMT are in

When I was compiling ruby-static-library I’ve used --disable-rubygems,
was that a problem?

My Engine code is on github if you need to look: