0

I've been attempting to follow this guide here for writing a program in C++ that allows me to create an application window, however I ran into an issue where whenever I used Run Build Task with MinGW-w64 on the example code provided on the page linked above, I keep running into this same error.

c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): undefined reference to 'WinMain@16'

collect2.exe: error: ld returned 1 exit status

The important part of that bit is the undefined reference to 'WinMain@16' at the end. Apparently because the sample code I tried uses wWinMain instead of WinMain, MinGW can't find any entry point? So this would mean I can't use MinGW if I want to run this code. So what do I do instead? What compiler would actually work for compiling wWinMain?

  • Did you try just changing the sample from `wWinMain` to `WinMain`? A "narrow" `WinMain` function can still call `W` versions of all API functions, so it may just work, or at most you may have to add a call to `GetCommandLineW()` instead of using the szCmdLine parameter (which is ANSI with the mingw library, instead of Unicode that the sample expects) – Ben Voigt May 13 '22 at 18:40
  • mingw-w64 is a fine toolchain for C++ on Windows. And if you install it with MSYS2, you get a lot of great libraries at your fingertips. And I'd suggest you just use WinMain or main unless you specifically need to do something with non-ASCII characters passed as arguments to your program. – David Grayson May 13 '22 at 18:40
  • 2
    Although it looks like recent versions of mingw have a `-municode` command-line option. It just doesn't auto-detect like the Microsoft tools do. – Ben Voigt May 13 '22 at 18:42
  • @DavidGrayson I don't want to use wrappers or install any more programs than I have to. I don't want to end up with a huge mess of programs, I want to keep things as simple and straightfowards as possible. About switching to WinMain: I tried removing the w from the function name so it was just WinMain and the build failed again so I'm not really sure what to do about that – Fez_Master May 13 '22 at 18:49
  • You'd certainly be better off following a mingw tutorial if you're using mingw – Alan Birtles May 13 '22 at 18:51
  • Use `-municode` as mentioned in the duplicate questions. – David Grayson May 13 '22 at 19:06

0 Answers0