| Summary: | undefined reference to 'WinMain@16' | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Matheus Vieira <matheusvf1234> |
| Component: | build | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED INVALID | QA Contact: | Sam Lantinga <slouken> |
| Severity: | critical | ||
| Priority: | P2 | CC: | admin, philipp.wiesemann |
| Version: | HG 2.1 | ||
| Hardware: | x86_64 | ||
| OS: | Windows (All) | ||
| Attachments: | Fixing the bug | ||
|
Description
Matheus Vieira
2016-05-26 23:18:47 UTC
__WIN32__ is a macro defined by SDL for 32 bit and 64 bit (in "SDL_platform.h"). The problem with WinMain() might be fixed by accident with __WIN__ if this macro is not defined. This would lead to the same result like defining SDL_MAIN_HANDLED before including "SDL.h" (as pointed out in the linked Stack Overflow post). It looks like this can be resolved by checking to make sure you're defining main() properly and including SDL.h in that file. Okay, can you clarify the error more detailed? I still have this error, look:
- We have a MinGW or MinGW-w64 toolchain
- We have a simple code called as "meow.c"
```
#include "SDL.h"
#include "SDL_log.h"
int main(int argc, char *arvg[])
{
SDL_Log("Meow!");
return 0;
}
```
- We have the latest SDL2 built via CMake (or by AutoTools)
- Trying to build it by the next command:
```
>gcc meow.c -o meow.exe -IWhereIsSDL/include/SDL2 -LWhereIsSDL/lib -lSDL2main -lSDL2 -mconsole
```
And the result is:
```
lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e):
undefined reference to `WinMain'
```
Can anyone HERE explain how to CORRECTLY declare the main function and how to link it to make SDLmain work?
This is a different error, but just by looking at it, it seems you might be able to fix it like this:
gcc meow.c -o meow.exe -IWhereIsSDL/include/SDL2 -LWhereIsSDL/lib -lmingw32 -lSDL2main -lSDL2 -mconsole
It's interesting that it's missing WinMain instead of WinMain@16, which means it's probably using cdecl instead of stdcall calling convention. SDL currently doesn't support that, but it would be easy to add if that's the case.
Try editing src/main/windows/SDL_windows_main.c and adding this at the bottom:
int
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
{
return main_getcmdline();
}
and let us know if that works?
Going to try that... BTW: I think this should also work in MSVC too I guess... Okay, that doesn't matter, the -lmingw32 contains another "WinMain" symbol with a different code that is needed for MinGW itself. So, we should document that for MinGW case we should link "-lmingw32" before SDL2main and SDL2 for a correct work of thing. |