# Ruby extension issue

**URL:** <https://www.ruby-forum.com/t/ruby-extension-issue/80583>\
**Category:** Ruby\
**Created:** [December 28, 2006, 10:15pm UTC](https://www.ruby-forum.com/t/ruby-extension-issue/80583 "2006-12-28T22:15:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wim\_Vander\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/13edae/32.png) [@Wim\_Vander\_S](https://www.ruby-forum.com/u/Wim_Vander_S)\
**Post date:** [December 28, 2006, 10:15pm UTC](https://www.ruby-forum.com/t/ruby-extension-issue/80583/1 "2006-12-28T22:15:47Z")

</div>

Hi,

I am playing around with building ruby extensions in C but I have a  
problem.  
I’m trying to make some bindings to SDL, and everything compiles fine,  
but when I load the extension in IRB, I get the following:

```
irb(main):001:0> require 'gamer'
irb: symbol lookup error: ./gamer.so: undefined symbol: SDL_Init

```

My C code is:

```
#include <stdio.h>
#include <ruby.h>
#include <SDL/SDL.h>

static VALUE rb_mGamer;
static VALUE rb_cScreen;

void Init_gamer()
{
    // Create a Gamer module and a Screen class within it
    rb_mGamer = rb_define_module("Gamer");
    rb_cScreen = rb_define_class_under(rb_mGamer, "Screen", 

```

rb\_cObject);

```
    // Try and initialize SDL
    Sint32 init_res = SDL_Init(SDL_INIT_EVERYTHING);

    // If not everything went as planned, log the error
    if(init_res < 0)
    {
        if(rb_respond_to(rb_mGamer, rb_intern("log")))
            rb_funcall(rb_mGamer, rb_intern("log"), 1,
rb_str_new2(SDL_GetError()));
    }

    // See what was initialized and set the appropriate flags to
true or false
    Uint32 winit = SDL_WasInit(SDL_INIT_EVERYTHING);

    if(winit & SDL_INIT_AUDIO)
    {
        rb_define_const(rb_mGamer, "audio", Qfalse);
    } else {
        rb_define_const(rb_mGamer, "audio", Qtrue);
    }
}

```

Do I have to tell ruby to load the SDL library as well when loading my  
extension?

Thanks in advance,

Wim

–  
Wim Vander S.  
Bachelor Computer Science, University Ghent

[http://nanoblog.ath.cx](http://nanoblog.ath.cx)  
My weblog, powered by Ruby and BSD licensed.
