Home > Article > Backend Development > Why does MinGW throw an "undefined reference to WinMain" error when using wWinMain in C ?
Resolving undefined reference to WinMain when using wWinMain in C (MinGW)
When attempting to use wWinMain (HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) as the program entry point in C under MinGW, an "undefined reference to WinMain" error can occur.
Cause:
MinGW, particularly older versions, does not natively support the wWinMain entry point, which expects a wide-character (WCHAR) command line argument.
Solution:
There are two potential solutions:
1. Use -municode Flag:
Newer versions of MinGW support the -municode linker flag, which switches to an alternate startup code that allows using wWinMain. Add this flag to your command line, linker options in your IDE, or Makefile:
g++ other_options_and_arguments -municode
2. Use WinMain Entry Point:
For older versions of MinGW or if you prefer not to use the -municode flag, you can revert to using the standard WinMain entry point. This requires modifying your code as follows:
Additional Note:
If you need to access Unicode command line arguments later in your program, use LPWSTR cmd_line = GetCommandLineW(); instead of using the WinMain argument.
The above is the detailed content of Why does MinGW throw an "undefined reference to WinMain" error when using wWinMain in C ?. For more information, please follow other related articles on the PHP Chinese website!