Undefined Reference to WinMain in C MinGW
When attempting to compile a Windows application using C in MinGW, you may encounter the error "undefined reference to WinMain." This error arises when you try to use the wWinMain entry point instead of the standard WinMain entry point.
To resolve this issue, newer versions of MinGW support the -municode linker option. Adding this option to your command line or linker options in your IDE or makefile will instruct the compiler to use alternative startup code that supports wWinMain.
g++ other_options_and_arguments -municode
However, older versions of MinGW do not have this option. In such cases, you should use the standard WinMain entry point and obtain the command line arguments using the GetCommandLine() function.
In the specific case you encountered, you can simply replace wWinMain with WinMain and PWSTR pCmdLine with PSTR pCmdLine. This will resolve the compilation error because the program does not utilize the pCmdLine value.
If you require unicode command line arguments in the future, consider using LPWSTR cmd_line = GetCommandLineW(); instead of using it as an argument to WinMain.
The above is the detailed content of Why Am I Getting an 'undefined reference to WinMain' Error in MinGW C ?. For more information, please follow other related articles on the PHP Chinese website!