Home > Backend Development > C++ > body text

Why do I get an 'undefined reference to WinMain' error when using wWinMain in MinGW?

Patricia Arquette
Release: 2024-11-06 03:32:02
Original
908 people have browsed it

Why do I get an

Mitigating Undefined Reference to WinMain when Employing wWinMain in C MinGW

When attempting to create a Windows application in C using MinGW (GCC), users may encounter an undefined reference to WinMain if they opt to utilize wWinMain instead of int main(). This error arises because MinGW's CRT startup library does not support wWinMain.

Solution:

Newer versions of MinGW provide the -municode linker option, enabling the switch to alternate startup code that permits the usage of wWinMain instead of WinMain. Incorporating this option into the command line, linker options in IDE, or makefile should resolve the issue:

g++ other_options_and_arguments -municode
Copy after login

However, it's worth noting that older MinGW versions lack support for this option. In such cases, consider using WinMain instead. In the provided example, since the program does not utilize the pCmdLine value, modifying wWinMain to WinMain and PWSTR pCmdLine to PSTR pCmdLine should suffice for compilation.

Unicode Command Line Handling:

If you later require Unicode command line handling, employ LPWSTR cmd_line = GetCommandLineW(); instead of WinMain argument.

The above is the detailed content of Why do I get an 'undefined reference to WinMain' error when using wWinMain in MinGW?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!