Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to WinMain@16 when using SDL

I've been having a lot of trouble getting everything working so that I can start developing on Windows, as apposed to Linux, which is what I normally use when coding. I'm having a rather bizarre issue when trying to compile an SDL program. As soon as I include the SDL library, the program refuses to compile, giving me this error:

c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a<main.o>: In function 'main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to 'WinMain@16'
collect2: ld returned 1 exist status

I am using MinGW on console.

To give an example, using

gcc -o test main.c

This compiles fine:

#include <stdio.h>
#include <stdlib.h>

int main(int argv, char **argc)
{
    printf("Hello, world!\n");

    return 0;
}

But as soon as I add #include (even without any SDL functions being called) I get the error mentioned above

Using:

gcc -o test main.c -lSDL

This fails to compile:

#include <stdio.h>
#include <stdlib.h>

#include <SDL/SDL.h>

int main(int argv, char **argc)
{
    printf("Hello, world!\n");

    return 0;
}

Any help would be greatly appreciated! I read that this was a common issue for people who forget to have a main function, but obviously that's not my issue. I also heard that WinMain is the main function used when dealing with Windows graphical programs, but that's never been an issue for me in the past when I used to develop in Windows more.

like image 913
Velovix Avatar asked Aug 07 '13 22:08

Velovix


1 Answers

I did a little bit of searching for some more information on this error, and I found this page which includes the following informaion:

The only trick in getting this to compile now is to add the include path (eg: -I../SDL/include), the linker path (eg: -L../SDL/lib), and then finally adding the libraries themselves in the right order. Use:

-lmingw32 -lSDLmain -lSDL

Also, don't forget to add the -mwindows flag, if your IDE doesn't add it automatically (in addition to whatever other libraries you want to link). If you don't put them in the right order, you'll get a linker error complaining about the missing symbol WinMain@16.

Try recompiling with those flags above and see whether that makes a difference.

like image 98
WhoBuntu Avatar answered Oct 19 '22 03:10

WhoBuntu