LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-04-2007, 10:46 AM   #1
aatwell
Member
 
Registered: Apr 2007
Location: San Jose, CA
Posts: 31

Rep: Reputation: 15
Question 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.
 
Old 12-04-2007, 10:54 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Are you linking the library as well?
 
Old 12-04-2007, 11:14 AM   #3
aatwell
Member
 
Registered: Apr 2007
Location: San Jose, CA
Posts: 31

Original Poster
Rep: Reputation: 15
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);
}
 
Old 12-04-2007, 12:00 PM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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.
 
Old 12-04-2007, 12:21 PM   #5
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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?

Last edited by dmail; 12-04-2007 at 12:32 PM. Reason: a little more helpful
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined reference, why? george_mercury Programming 4 05-07-2009 12:15 AM
Undefined reference to: ashlesha Programming 5 11-08-2006 01:07 PM
undefined reference? Sharky01252 Programming 3 11-07-2006 11:36 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 03:01 AM
undefined reference mp4-10 Programming 3 01-25-2005 12:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration