无法使用 Mingw 编译 win32 C++
Can not compile win32 C++ Using Mingw
我想开始学习 win32 api 但 g++ 总是 return 和
undefined reference to `WinMain@16'
我从这里复制了微软网站上的 cpp 代码 - Link。我尝试了多个其他来源的“Hello World”但没有运气。我该怎么办?
您可以在 WinAPI 中使用两种类型的入口函数:WinMain
和 wWinMain
。
The WinMain
function is identical to wWinMain
, except the command-line arguments are passed as an ANSI string. The Unicode version is preferred.
两者都应该与 Microsoft Visual C++ 编译器一起工作。但是,MinGW 和 wWinMain
函数存在一些问题。
解决方案 1:使用 Microsoft Visual C++ 编译器。
解决方案 2:使用 MinGW 并将入口点函数更改为 WinMain
因为它在 MinGW 上可以正常工作(同时将 PWSTR pCmdLine
更改为 PSTR pCmdLine
):
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR pCmdLine, int nCmdShow)
^^^^^^^ ^^^^
解决方案3:讨论here但我没有测试。
如果你使用的是MinGW-w64,可以添加
-municode
作为命令行选项。您的原始源代码应该可以正确编译。
我想开始学习 win32 api 但 g++ 总是 return 和
undefined reference to `WinMain@16'
我从这里复制了微软网站上的 cpp 代码 - Link。我尝试了多个其他来源的“Hello World”但没有运气。我该怎么办?
您可以在 WinAPI 中使用两种类型的入口函数:WinMain
和 wWinMain
。
The
WinMain
function is identical towWinMain
, except the command-line arguments are passed as an ANSI string. The Unicode version is preferred.
两者都应该与 Microsoft Visual C++ 编译器一起工作。但是,MinGW 和 wWinMain
函数存在一些问题。
解决方案 1:使用 Microsoft Visual C++ 编译器。
解决方案 2:使用 MinGW 并将入口点函数更改为 WinMain
因为它在 MinGW 上可以正常工作(同时将 PWSTR pCmdLine
更改为 PSTR pCmdLine
):
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR pCmdLine, int nCmdShow)
^^^^^^^ ^^^^
解决方案3:讨论here但我没有测试。
如果你使用的是MinGW-w64,可以添加
-municode
作为命令行选项。您的原始源代码应该可以正确编译。