littlewolf icon indicating copy to clipboard operation
littlewolf copied to clipboard

How to build on Windows?

Open yektasarioglu opened this issue 5 years ago • 3 comments

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.

yektasarioglu avatar Aug 03 '19 18:08 yektasarioglu

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.

servusdei2018 avatar Aug 08 '19 16:08 servusdei2018

@yektasarioglu: Add -lSDL2main to the command line, that's where WinMain lives in this setup.

xparq avatar Aug 21 '19 19:08 xparq

Include the definition of

#define SDL_MAIN_HANDLED

before importing the SDL library

image

AdfalomnLaeninfus avatar Nov 05 '23 05:11 AdfalomnLaeninfus