目前,我正在尝试使用 C++ 制作一个 Windows 应用程序。为了编译我的程序,我使用 MinGW (GCC)。但只要我使用 int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
而不是 int main()
编译器就会向我显示以下消息:
C:/mingw-w64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status The terminal process terminated with exit code: 1
我尝试编译的示例代码来自此 Windows 应用程序教程: 示例代码
我已经尝试重新安装 MinGW,但没有帮助(我也在使用 Windows 10)。
原文由 wuzipu 发布,翻译遵循 CC BY-SA 4.0 许可协议
此示例代码使用
wWinMain
但是通过 使用 MinGW 构建 Win32 GUI 应用程序
在这种特定情况下,您可以使用
WinMain
代替。 This program doesn’t usepCmdLine
value, so it should compile when you changewWinMain
toWinMain
andPWSTR pCmdLine
toPSTR pCmdLine
.如果您以后需要 unicode 命令行,请使用
LPWSTR cmd_line = GetCommandLineW();
而不是WinMain
参数。Newer Mingw versions also support
-municode
linker option switching to alternate startup code allowing to usewWinMain
instead ofWinMain
(orwmain
instead ofmain
)。将其添加到命令行、IDE 或 makefile 中的链接器选项。