We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5281 - Undefined reference to 'WinMain'
Summary: Undefined reference to 'WinMain'
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: build (show other bugs)
Version: 2.0.13
Hardware: x86_64 Other
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-04 14:08 UTC by Gwilherm Baudic
Modified: 2020-09-04 14:08 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gwilherm Baudic 2020-09-04 14:08:45 UTC
This is a very specific bug I encountered when trying to build example programs of a library using Scons under MSYS2 (64 bit version). Although this is actually a version of SDL 2.0.12 with some patches from 2.0.13 which was rebuilt by the MSYS2 team, I think this bug should actually be fixed here. 

Version 2.0.12-4 worked fine, but the bug started to appear in 2.0.12-5. The only difference between both is the application of a patch based on Hg commit id fc03d19926ed in the SDL repository. 

The error message I get now is:
g++ -o examples/sdl2widgets.exe -Wl,-no-undefined -mwindows -Wl,--no-undefined examples/sdl2widgets.o -Lsrc -L/mingw64/lib -lguisan -lSDL2_image -lSDL2_ttf -lSDL2main -lSDL2 -lmingw32 -ldxerr8 -ldinput8 -lshell32 -lsetupapi -ladvapi32 -luuid -lversion -loleaut32 -lole32 -limm32 -lwinmm -lgdi32 -luser32 -lm
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function `main':
D:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
scons: *** [examples/sdl2widgets.exe] Error 1
scons: building terminated because of errors.

After some digging, scons takes its library list in this case from a call to pkg-config, which itself relies on the contents of the generated sdl2.pc file. It turns out that in this file, and despite applying the patch fc03d19926ed, a library still appears both in the Libs and in the Libs.private section: mingw32. Consequently, the call to pkg-config --cflags --libs sdl2 contains both the Libs and the Libs.private section in this order, but the subsequent use of the ParseConfig method in scons only leaves the rightmost instance of -lmingw32 in the compilation line. Editing manually the compilation command to put -lmingw32 BEFORE -lSDL2main solves the error. 

My guess here is that to fix this issue, line 1577 of the CMakeLists.txt file (which reads  list(APPEND EXTRA_LIBS mingw32)) should be removed.