littlewolf
littlewolf copied to clipboard
How to build on Windows?
I was trying to run makefile and I got an error that says;
gcc -std=c99 -Wall -Wextra -pedantic -Ofast -flto -march=native -lm -lSDL2 main.c -o littlewolf
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
make: *** [Makefile:12: all] Error 1
Any help would be appreciated. Thanks.
Synopsis
undefined reference to 'WinMain@16'
tells us that the compiler can't find the entrypoint for littlewolf, even though it's declared int main(int argc, char* argv[])
. Perhaps this is caused by SDL declaring its own entrypoint, but I think this is caused by the compiler trying to find a GUI entrypoint for a console project.
Possible Solution
As I don't have a detailed understanding of the Windows subsystem, I'll propose a workaround. Try renaming main.c
to main.cpp
, and using Visual Studio to create a new console application, import main.cpp
, and build. I believe @mottosso was able to do this.
@yektasarioglu: Add -lSDL2main
to the command line, that's where WinMain
lives in this setup.
Include the definition of
#define SDL_MAIN_HANDLED
before importing the SDL library