問題描述
目前我正在嘗試使用 C++ 制作一個 Windows 應用程序.為了編譯我的程序,我使用 Mingw GCC.順便說一句,我在 Windows 10 上.但是一旦我使用 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):對WinMain" collect2.exe 的未定義引用:錯誤:ld 返回 1退出狀態終端進程以退出代碼終止:1
我嘗試編譯的示例代碼來自此 Windows 應用程序教程:示例代碼
我已經嘗試重新安裝 mingw,但沒有幫助.這就是為什么我希望這里有人可以幫助我解決我的問題.提前謝謝你!
此示例代碼使用 wWinMain
但
需要注意的一點是 Visual C++ 支持wWinMain"入口點其中lpCmdLine"參數是LPWSTR".您通常會使用入口點的_tWinMain"預處理器定義和聲明LPTSTR lpCmdLine",以便您可以輕松地同時支持 ANSI和 Unicode 構建.但是,MinGW CRT 啟動庫沒有支持 wWinMain,所以你必須堅持使用標準的WinMain"如果需要訪問命令行,請使用GetCommandLine()"參數.
通過 使用 MinGW 構建 Win32 GUI 應用程序>
在這種特定情況下,您可以改用 WinMain
.這個程序不使用pCmdLine
值,所以當你把wWinMain
改為WinMain
和PWSTR pCmdLine
時它應該編譯到 PSTR pCmdLine
.
如果您以后需要 unicode 命令行,請使用 LPWSTR cmd_line = GetCommandLineW();
而不是 WinMain
參數.
較新的 Mingw 版本還支持 -municode
鏈接器選項切換到備用啟動代碼,允許使用 wWinMain
而不是 WinMain
(或 wmain
而不是 main
).將其添加到命令行、IDE 或 makefile 中的鏈接器選項.
g++ other_options_and_arguments -municode
currently I am trying to make a windows application using c++. For compiling my program I use Mingw GCC. Btw I'm on Windows 10.
But as soon as I use int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
instead of int main()
the compiler shows me following message:
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
The example code I tried to compile I got from this Windows application tutorial: Example Code
I have already tried reinstalling mingw but it did not help. That's why i hoped someone here could help me with my problem. Thank you in advance!
This example code uses wWinMain
but
One thing to note is that Visual C++ supports a "wWinMain" entry point where the "lpCmdLine" parameter is a "LPWSTR". You would typically use the "_tWinMain" preprocessor definition for your entry point and declare "LPTSTR lpCmdLine" so that you can easily support both ANSI and Unicode builds. However, the MinGW CRT startup library does not support wWinMain, so you’ll have to stick with the standard "WinMain" and use "GetCommandLine()" if you need to access command line arguments.
via Building Win32 GUI Applications with MinGW
In this specific case, you can use WinMain
instead. This program doesn't use pCmdLine
value, so it should compile when you change wWinMain
to WinMain
and PWSTR pCmdLine
to PSTR pCmdLine
.
If you later would need unicode command line use LPWSTR cmd_line = GetCommandLineW();
instead of WinMain
argument.
Newer Mingw versions also support -municode
linker option switching to alternate startup code allowing to use wWinMain
instead of WinMain
(or wmain
instead of main
). Add it to your command line, linker options in IDE or makefile.
g++ other_options_and_arguments -municode
這篇關于對 WinMain (C++ Mingw) 的未定義引用的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!