Search code examples
c++sdl

SDL 2 Undefined Reference to "WinMain@16" and several SDL functions


I've just installed SDL 2 and I have some serious problems. This is my code:

#include <SDL2\SDL.h>

int main(int argc, char* argv[]) {
    SDL_Init(SDL_INIT_VIDEO);
    SDL_Quit();
    return 0;
}

I am unable to compile because I get the error described in the title:

obj\Debug\main.o||In function SDL_main':|  
C:\Users\myuser\Desktop\test 2000\main.cpp|5|undefined reference to SDL_Init'|
C:\Users\myuser\Desktop\test 2000\main.cpp|7|undefined reference to SDL_Quit'|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(main.o):main.c|| undefined reference to WinMain@16'|  
||=== Build finished: 3 errors, 0 warnings ===|

Solution

  • post the compiler commands. ex: g++/gcc ....

    you are probably not linking the library.

    http://content.gpwiki.org/index.php/SDL:Tutorials:Setup you should have the path to the lib, included in the ide. (I see you are using codeblocks)

    add to the linker settings: -lmingw32 -lSDLmain -lSDL

    http://www.sdltutorials.com/sdl-tutorial-basics