User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,543 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,305 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2912 | Replies: 7
Reply
Join Date: Oct 2007
Posts: 18
Reputation: MedianHansen is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
MedianHansen MedianHansen is offline Offline
Newbie Poster

[Linker error] undefined reference to `SDL_Init'

  #1  
Oct 14th, 2007
At first, here's my source code:
#include <SDL.h>

int main(int argc, char* argv[])
{
 //initialize SDL and the video system.
 if (SDL_Init( SDL_INIT_VIDEO)<0)
 return -1;
 
 //signal SDL to change the text of the main window to SDL "Hello World".
 SDL_WM_SetCaption("Hello world","Hello World");
 
 //Create an SDL_Surface object, which represents, the game window.
 SDL_Surface* screen=SDL_SetVideoMode(640,480,0,0);
 
 //Load the SDL logo bitmap to a temporary surface
 SDL_Surface* temp=SDL_LoadBMP("data\\structures\\sdl_logo.bmp");
 
 //Create the working SDL surface which matches the display format of the temporary surface.
 SDL_Surface* bg= SDL_DisplayFormat(temp);
 
 //Free the memory allocated to the temporary SDL_Surface.
 SDL_FreeSurface(temp);
 
 SDL_Event event;
 bool quit=false;
 
 //this is the main message loop if the game.
 while(!quit)
 {
   //Check message qeue for an event.
   if (SDL_PollEvent(&event))
   {
     //If an event was found.
     switch (event.type)
     {
       //check to see if the window was closed via the "x"
       case SDL_QUIT:
       //Set the quit flag to true
       quit=true;
       break;
       
      //Check the keyboard to see if the ESC key was pressed.
      case SDL_KEYDOWN:
       switch (event.key.keysym.sym)
       {
         case SDLK_ESCAPE:
           //set our quit flag to true
           quit=true;
          break;
       }
      break; 
     }
   } 
   //Draw the background sprite:
   SDL_BlitSurface(bg, NULL, screen, NULL);   
   
   //Update the current window.
   SDL_UpdateRect(screen,0,0,0,0);      
 }

//Free the allocated memery for the background surface.
SDL_FreeSurface(bg);

//Quit SDL and allow it to clean up everything.
SDL_Quit();

//return control to windows with no errors.
return 0;
}
Well... my problem is, that i in some way must have mis-configured, my compiler. But since i'm new (Both at programming c++ and at using the compiler), i don't know how
the error meesages are, the following:
[Linker error] undefined reference to `SDL_Init'
[Linker error] undefined reference to `SDL_WM_SetCaption'
[Linker error] undefined reference to `SDL_SetVideoMode'
[Linker error] undefined reference to `SDL_RWFromFile'
[Linker error] undefined reference to `SDL_LoadBMP_RW'
[Linker error] undefined reference to `SDL_DisplayFormat'
[Linker error] undefined reference to `SDL_FreeSurface'
[Linker error] undefined reference to `SDL_PollEvent'
[Linker error] undefined reference to `SDL_UpperBlit'
[Linker error] undefined reference to `SDL_UpdateRect'
[Linker error] undefined reference to `SDL_FreeSurface'
[Linker error] undefined reference to `SDL_Quit'
[Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status
As you can see, any command that i have used, which starts with SDL, has an undefinded referance. As i have come to understand, it has something to do with the way i have inclueded my files.
If some-one out there have used the dev-c++ compiler (Which i'm using), and also have experiaence with connecting that compiler to the SDL, it would be REALY nice if you would give me a, step, by step, tutorial, in how to do it. But it would also be nice if any1 else would bother to anwser, because that might be enouth to help me.
Please take in notice, that i'm VERY new to the langauge and compiler, so please don't use any words/sentences, that only experienced users understand
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,832
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 324
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: [Linker error] undefined reference to `SDL_Init'

  #2  
Oct 14th, 2007
I think the question here is, if anyone can be bothered to download SDL to test it.

Personally, I don't think anyone is going to do that. Btw I have dev-cpp
Last edited by iamthwee : Oct 14th, 2007 at 8:51 am.
... the hat of 'is this a cat in a hat?'
Reply With Quote  
Join Date: Dec 2006
Location: india
Posts: 1,085
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Rep Power: 9
Solved Threads: 163
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: [Linker error] undefined reference to `SDL_Init'

  #3  
Oct 14th, 2007
here is something obtained thru googling (i've no clue about either dev-c++ or sdl); see if these help.
http://www.gpwiki.org/index.php/C:Ho...s:_Dev-C.2B.2B
http://www.imrtechnology.ngemu.com/sdldevtut.htm
if they do not, abandon daniweb and try a forum where there may be people who are more knowledgable. eg. http://gpwiki.org/forums/viewforum.php?f=2
Reply With Quote  
Join Date: Oct 2007
Posts: 18
Reputation: MedianHansen is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
MedianHansen MedianHansen is offline Offline
Newbie Poster

Re: [Linker error] undefined reference to `SDL_Init'

  #4  
Oct 14th, 2007
Well... ty both, that seemewd to help, but now i'm getting some strange new errors Which i don't understand...

multiple definition of `main'
first defined here
.drectve `/DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"MSVCRT" /DEFAULTLIB:"OLDNAMES" ' unrecognized
[Linker error] undefined reference to `_alloca_probe'
[Linker error] undefined reference to `_alloca_probe'
[Linker error] undefined reference to `_alloca_probe' (Yeah, this error comes three times)
ld returned 1 exit status
C:\Dev-Cpp\Projekt hej\Makefile.win [Build Error] [HEJ.exe] Error 1

The two last errors should correct themselves, if the others are corrected (At least thats what i have come to understand).
But i don't understand that it says i have two main functions, cause i don't
and neither do i understand the '_alloca_probe', i haven't even used it in my source code:
#include <SDL.h>

int main(int argc, char* argv[])
{
 //initialize SDL and the video system.
 if (SDL_Init( SDL_INIT_VIDEO)<0)
 return -1;
 
 //signal SDL to change the text of the main window to SDL "Hello World".
 SDL_WM_SetCaption("Hello world","Hello World");
 
 //Create an SDL_Surface object, which represents, the game window.
 SDL_Surface* screen=SDL_SetVideoMode(640,480,0,0);
 
 //Load the SDL logo bitmap to a temporary surface
 SDL_Surface* temp=SDL_LoadBMP("data\\structures\\sdl_logo.bmp");
 
 //Create the working SDL surface which matches the display format of the temporary surface.
 SDL_Surface* bg= SDL_DisplayFormat(temp);
 
 //Free the memory allocated to the temporary SDL_Surface.
 SDL_FreeSurface(temp);
 
 SDL_Event event;
 bool quit=false;
 
 //this is the main message loop if the game.
 while(!quit)
 {
   //Check message qeue for an event.
   if (SDL_PollEvent(&event))
   {
     //If an event was found.
     switch (event.type)
     {
       //check to see if the window was closed via the "x"
       case SDL_QUIT:
       //Set the quit flag to true
       quit=true;
       break;
       
      //Check the keyboard to see if the ESC key was pressed.
      case SDL_KEYDOWN:
       switch (event.key.keysym.sym)
       {
         case SDLK_ESCAPE:
           //set our quit flag to true
           quit=true;
          break;
       }
      break; 
     }
   } 
   //Draw the background sprite:
   SDL_BlitSurface(bg, NULL, screen, NULL);   
   
   //Update the current window.
   SDL_UpdateRect(screen,0,0,0,0);      
 }

//Free the allocated memery for the background surface.
SDL_FreeSurface(bg);

//Quit SDL and allow it to clean up everything.
SDL_Quit();

//return control to windows with no errors.
return 0;
}
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 40
Solved Threads: 972
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: [Linker error] undefined reference to `SDL_Init'

  #5  
Oct 14th, 2007
_alloca_probe is probably being called from one of the library functions you call. That happens a lot.
<<Freelance Programmer>> << Hobby Site>>
Signature links for sale. PM me for details
Reply With Quote  
Join Date: Oct 2007
Posts: 18
Reputation: MedianHansen is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
MedianHansen MedianHansen is offline Offline
Newbie Poster

Re: [Linker error] undefined reference to `SDL_Init'

  #6  
Oct 14th, 2007
Yeah, i kinda thought that too... but how do i correct the error then?
Reply With Quote  
Join Date: Oct 2007
Posts: 18
Reputation: MedianHansen is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
MedianHansen MedianHansen is offline Offline
Newbie Poster

Re: [Linker error] undefined reference to `SDL_Init'

  #7  
Oct 14th, 2007
Okay... this is strange, the same errors comes, even if i break the source code down to:
#include <SDL.h>

int main(int argc, char* argv[])
{

}
Reply With Quote  
Join Date: Jan 2007
Location: Maryland, USA
Posts: 1,036
Reputation: Sturm is on a distinguished road 
Rep Power: 4
Solved Threads: 23
Sturm's Avatar
Sturm Sturm is offline Offline
Veteran Poster

Re: [Linker error] undefined reference to `SDL_Init'

  #8  
Oct 14th, 2007
try:
#include "SDL/SDL.h"
"Hey ass, don't hijack my thread. This is serious." -JoshSCH
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 5:00 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC