title: Ruby interpreter embed in C code
body: <p>I just try a simple example from a book:
  I have a sum.rb file:</p>
  
  <pre><code>class Summer
    def sum(max)
    raise "Invalid maximum #{max}" if max &lt; 0
    (max*max + max)/2
    end
  end
  </code></pre>
  
  <p>And a embed_sum.c file:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;ruby/ruby.h&gt;
  int main ( int argc, char ** argv) 
  {
    VALUE result;
    ruby_sysinit(&amp;argc, &amp;argv);
    RUBY_INIT_STACK;
    ruby_init();
    ruby_init_loadpath();
    rb_require("sum");
    rb_eval_string("$summer = Summer.new");
    rb_eval_string("$result = $summer.sum(10)");
    result = rb_gv_get("result");
    printf("Result = %d\n", NUM2INT(result));
    return ruby_cleanup(0);
  }
  </code></pre>
  
  <p>The I compile it with:</p>
  
  <pre><code>gcc -Wall -lruby -I/usr/include/ruby-1.9.1/  embed_sum.c -o embed_sum
  </code></pre>
  
  <p>When I launch ./embed_sum it gives me a segmentation fault from the first rb_eval_string.
  my version of ruby is : ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux] on Archlinux. </p>
  
  <p>What can be the problem with this example?</p>