Home >Backend Development >C++ >Why am I getting an Undefined Reference to WinMain@16 when using wWinMain with Mingw?

Why am I getting an Undefined Reference to WinMain@16 when using wWinMain with Mingw?

Barbara Streisand
Barbara StreisandOriginal
2024-11-05 10:59:021037browse

Why am I getting an Undefined Reference to WinMain@16 when using wWinMain with Mingw?

wWinMain, Unicode, and Mingw

In this discussion, a developer encounters an error using the wWinMain function with Mingw as their compiler. This guide will explore the issue and provide solutions to resolve the error and address the question of using Unicode.

Problem

The developer experiences an undefined reference to WinMain@16 when compiling the program using Mingw. Replacing wWinMain with Winmain and PWSTR with LPSTR resolves the issue, but the developer wants to know if there is a better solution and the significance of not using Unicode.

Solution

For older versions of Mingw, a wrapper called mingw-unicode-main can be used. It provides support for wmain and wWinMain when compiling Unicode programs. The instructions for using this wrapper can be found in the project's GitHub repository: https://github.com/coderforlife/mingw-unicode-main.

For newer versions of Mingw, the -municode option should be used, as indicated in the mingw-unicode-main readme. This option enables support for Unicode in Mingw-w64.

Unicode considerations

Using Unicode is not always a significant concern. For simple programs that only require ASCII character support, using regular (CHAR) or TCHAR is sufficient. However, if the program will handle non-ASCII characters or internationalization, using Unicode is recommended.

Resources

  • [mingw-unicode-main](https://github.com/coderforlife/mingw-unicode-main/)
  • [Installing MinGW-w64](https://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win32/Personal Builds/rubenvb/gcc-4.7-release/)

The above is the detailed content of Why am I getting an Undefined Reference to WinMain@16 when using wWinMain with Mingw?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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