LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   undefined reference to `SDL_Quit' (https://www.linuxquestions.org/questions/programming-9/undefined-reference-to-%60sdl_quit-604442/)

aatwell 12-04-2007 10:46 AM

undefined reference to `SDL_Quit'
 
/tmp/ccSHyKZe.o: In function `main':
mouse.c:(.text+0x27): undefined reference to `SDL_Init'
mouse.c:(.text+0x4b): undefined reference to `SDL_SetVideoMode'
mouse.c:(.text+0x9d): undefined reference to `SDL_Quit'
collect2: ld returned 1 exit status

Anyone know why I might get an error of undefined reference to SDL_Init, SDL_SetVideoMode, and SDL_Quit... even though I have

#include <SDL/SDL.h>

with the correct path to the file in my code.

Nylex 12-04-2007 10:54 AM

Are you linking the library as well?

aatwell 12-04-2007 11:14 AM

I am trying to compile the code below on Fedora Core 6 [even tried Fedora Core 7] with the command

gcc -lX11 -L/usr/X11R6/lib -I/usr/X11R6/include -o go.exe mouse.c


Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <SDL/SDL.h>

int main()
{
        int Quit=0;
        SDL_Event event;
        SDL_Init(SDL_INIT_VIDEO);
        SDL_SetVideoMode(320,200,0,0);

        typedef union
        {
                Uint8 type;
                SDL_ActiveEvent active;
                SDL_KeyboardEvent key;
                SDL_MouseMotionEvent motion;
                SDL_MouseButtonEvent button;
                SDL_JoyAxisEvent jaxis;
                SDL_JoyBallEvent jball;
                SDL_JoyHatEvent jhat;
                SDL_JoyButtonEvent jbutton;
                SDL_ResizeEvent resize;
                SDL_QuitEvent quit;
                SDL_UserEvent user;
                SDL_SysWMEvent syswm;
        } SDL_Event;
        SDL_MouseButtonEvent *button;

        while(!Quit){
                switch(event.type) {
                        case SDL_KEYDOWN:
                        case SDL_KEYUP:
                        case SDL_MOUSEMOTION:
                        case SDL_MOUSEBUTTONDOWN:
                        case SDL_MOUSEBUTTONUP:
                                printf("Mouse button %d released at (%d, %d)\n",
                                        button->button, button->x, button->y);
                                Quit=1;
                                break;
                        case SDL_JOYAXISMOTION:
                        case SDL_JOYHATMOTION:
                        case SDL_JOYBALLMOTION:
                        case SDL_JOYBUTTONDOWN:
                        case SDL_JOYBUTTONUP:
                                break;
                        default:
                                break;}}
        SDL_Quit();
        return(0);
}


Nylex 12-04-2007 12:00 PM

Doesn't look like you're linking SDL, only X11. See the documentation for how to link the SDL library, it may just be a case of using -lsdl or something similar, or there may be a program that'll generate the required flags for you.

dmail 12-04-2007 12:21 PM

See the SDL FAQ's and this type of question is one that I hate the most, as it translates to "I am too lazy to look for myself, will someone else do it for me?"

[rant off]If you did not know this was a linker error then simply by ctrl-c and ctrl-v into google (example:undefined reference to `SDL_Init') and this would have brought a vast number of similar posts from other people. Some of which would give the same response as I(small rant) others would be more informative and supply links and answers.

My I also ask why you are redefining the SDL events?


All times are GMT -5. The time now is 05:06 PM.