You're missing the main()
function (or WinMain()
).
If you do have one, you probably forgot to save your source code, and ended up compiling an empty file (without main()
).
You can use either main
or WinMain
. The error will always say WinMain
, which is a hed herring, you can always use either one on MinGW.
On MinGW, the choice of main
vs WinMain
is unrelated to the "subsystem" setting ("windows" vs "console") that other answer talks about. The subsystem only matters for this on the MSVC compiler.
If you're using SDL2:
Then the above doesn't apply to you, because SDL2 provides its own main
function. It renames yours to SDL_main
(via #define main SDL_main
) and calls it from theirs.
Then the error means that you forgot the -lSDL2main
linker flag.
If you do have, it, make sure that the flag order is correct: .c
/.cpp
/.o
files, then-lmingw32 -lSDL2main -lSDL2
.
If that still doesn't work, the version of SDL2 you're using is likely incompatible with your compiler. If you're using MSYS2, consider installing their version of SDL2 (which is guaranteed to be compatible). Otherwise, you're likely using x32 SDL2 with x64 compiler, or vice versa. The SDL2 files you've downloaded come in two directries: i686...
(x32) and x86_64
(x64), try both.
Defining SDL_MAIN_HANDLED
is never necessary if you do everything correctly.