Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

sdl

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 ===|
like image 773
Mihai Avatar asked Jun 11 '13 15:06

Mihai


3 Answers

I think you want

#define SDL_MAIN_HANDLED

in your main file, BEFORE the line

#include <SDL2/SDL.h>

from: https://stackoverflow.com/a/32343111/5214543

like image 175
k1988 Avatar answered Oct 31 '22 05:10

k1988


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

like image 20
adderly Avatar answered Oct 31 '22 03:10

adderly


You need to add these to linker libraries with the same order:

mingw32
SDL2main
SDL2

Note that the order is important.

like image 38
barribow Avatar answered Oct 31 '22 05:10

barribow