SDL ld returned 1 exit status
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(Run开发者_Python百科ning)
{
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 -lSDL
to your linker. If you are using Windows I believe you have to add -lSDLmain
too. 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 within OnInit()
? Otherwise your program will not run correctly.
First, make sure you are including SDL.h, which will look like this on most platforms:
#include "SDL.h"
If you're building on a Mac with Xcode, you'll want to use this instead:
#include <SDL/SDL.h>
Then make sure you've linked against the SDL framework:
- If you're using Visual Studio (Windows), right-click the project and bring up the Properties, then under Configuration Properties > Linker > Input, make sure Additional Dependencies is SDL.lib SDLmain.lib.
- If you're using Xcode (Mac), find SDL.framework (probably under /Library/Frameworks) and drag it to your project's Frameworks folder.
- If you're invoking GCC from the command-line, link to libSDL.a and libSDLmain.a by adding -lSDL -lSDLmain to your command-line.
精彩评论