im writing a sample SDL program, and I just wrote the simplest program, but i get the following error because of my SDL_pollevent() function:
Test.cpp:(.text._ZN4CApp9OnExecuteEv[CApp::OnExecute()]+0x41): undefined reference to `SDL_PollEvent'
collect2: ld returned 1 exit status
and the code is:
int OnExecute()
{
if(OnInit()==false)
return -1;
SDL_Event Event;
while(Running)
{
while(SDL_PollEvent(&Event))
{
OnEvent(&Event);
}
OnLoop();
OnRend();
}
OnClean();
return 0;
}
This is a linker error. You are not correctly linking the SDL libraries to your project. Usually you would need to add
-lSDLto your linker. If you are using Windows I believe you have to add-lSDLmaintoo. Make sure your compiler knows where to find these files (set your library path correctly). If you don’t know how to do this, check the system and IDE specific installation instructions in this tutorial.I assume that
SDL_Init()is called withinOnInit()? Otherwise your program will not run correctly.