title: How to compile an mruby example?
body: <p>Hearing about <a href="https://github.com/mruby/mruby" rel="nofollow">mruby</a> has inspired me to start learning C programming. I have worked through a few tutorials online so I understand the basics, but now I would like to start playing with mruby by compiling an example application. I understand how to compile a single C file, but I'm stuck at trying to figure out how to also compile mruby along with my own code.</p>
  
  <p>I'm using GCC on Mac OS X 10.8.</p>
  
  <p>Using this example:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  
  #include &lt;mruby.h&gt;
  #include &lt;mruby/compile.h&gt;
  
  int main(void)
  {
    mrb_state *mrb = mrb_open();
    char code[] = "p 'hello world!'";
    printf("Executing Ruby code from C!\n");
  
    mrb_load_string(mrb, code);
    return 0;
  }
  </code></pre>
  
  <p>And running this command:</p>
  
  <pre><code>gcc example.c
  </code></pre>
  
  <p>I obviously get the error:</p>
  
  <pre><code>engine.c:4:19: error: mruby.h: No such file or directory
  </code></pre>
  
  <p>I have cloned the git repo and created a symlink to the include directory, but I'm pretty sure I'm doing it wrong.</p>
  
  <p>How should I include mruby in my code so that it's all compiled together?</p>
  
  <p><strong>Update:</strong> Here is the directory structure of what I have, note the symlink to the mruby include directory:</p>
  
  <pre><code>$ tree -l .
  .
  ├── example.c
  └── include
      └── mruby -&gt; ../../mruby/include
          ├── mrbconf.h
          ├── mruby
          │   ├── array.h
          │   ├── class.h
          │   ├── compile.h
          │   ├── data.h
          │   ├── debug.h
          │   ├── dump.h
          │   ├── gc.h
          │   ├── hash.h
          │   ├── irep.h
          │   ├── khash.h
          │   ├── numeric.h
          │   ├── proc.h
          │   ├── range.h
          │   ├── string.h
          │   ├── value.h
          │   └── variable.h
          └── mruby.h
  </code></pre>
  
  <p>When I compile by including the directory:</p>
  
  <pre><code>gcc example.c -I include/mruby
  </code></pre>
  
  <p>I get the following errors:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "_mrb_load_string", referenced from:
        _main in ccd8XYkm.o
    "_mrb_open", referenced from:
        _main in ccd8XYkm.o
  ld: symbol(s) not found for architecture x86_64
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p><strong>Update:</strong> I followed the instructions in the <code>mruby/INSTALL</code> file (which basically just said run make in the root directory of the mruby project). This added a bunch of directories and field in the <code>mruby/build/host</code> directory, including the file <code>lib/libmruby.a</code>. I was able to compile the example script by including this file when compiling.</p>
  
  <pre><code>gcc -Iinclude/mruby example.c ../mruby/build/host/lib/libmruby.a
  </code></pre>
  
  <p>Now I run my app:</p>
  
  <pre><code>$ ./a.out
  Executing Ruby code from C!
  "hello world!"
  </code></pre>