Forum: Ruby Ruby extension issue

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ae9705d43819ffe40a6936aeaf71205b?d=identicon&s=25 Wim Vander Schelden (Guest)
on 2006-12-28 22:15
(Received via mailing list)
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 Schelden
Bachelor Computer Science, University Ghent

http://nanoblog.ath.cx
My weblog, powered by Ruby and BSD licensed.
This topic is locked and can not be replied to.