简体   繁体   English

在MinGW编译器中,-mwindows命令是什么,它有什么作用?

[英]In the MinGW compiler, what is the -mwindows command, and what does it do?

I was having an issue with a C++ program where when I ran the .exe the program would run and my window for the program would open, but the console would be open on the desktop in the background.我遇到了一个 C++ 程序的问题,当我运行 .exe 时,程序会运行,我的程序窗口会打开,但控制台会在后台在桌面上打开。 I did a google search and found that compiling with the -mwindows command as an argument, removes the console.我进行了谷歌搜索,发现使用 -mwindows 命令作为参数进行编译会删除控制台。 Which it did.它做到了。 But I'm unsure of what it actually does and I am curious.但我不确定它实际上做了什么,我很好奇。

It behaves exactly the same as the /subsystem:windows switch described on MSDN .它的行为与MSDN 上描述的/subsystem:windows开关完全相同。

Basically, it sets the entry point to WinMain (or wWinMain ) instead of main (or wmain ), which results in no console window and some Win32 startup code running to create the arguments passed to WinMain .基本上,它将入口点设置为WinMain (或wWinMain )而不是main (或wmain ),这导致没有控制台窗口和运行一些 Win32 启动代码来创建传递给WinMain的参数。 As Neil says, it does not prevent or enable anything you can't do without it.正如 Neil 所说,它不会阻止或启用您没有它就无法完成的任何事情。

A similar switch is -municode to switch between main / WinMain and wmain / wWinMain , which is not mirrorred by the Microsoft tools.一个类似的开关是-municode用于在main / WinMainwmain / wWinMain之间切换,微软工具没有镜像。 These seem to automagically select the one you use).这些似乎会自动选择您使用的那个)。

It says that your application is one using the Win32 API that doesn't need a console window.它说您的应用程序是使用不需要控制台窗口的 Win32 API 的应用程序。 You use this option when you are writing Windows GUI applications, DLLs and the like, although a console window can be useful when debugging these kinds of applications.当你正在编写的Windows GUI应用程序,DLL和等,但调试这些类型的应用程序时,控制台窗口可能是有用的,你使用这个选项。 Even with this option, you can explicitly create a console window, should your application need one dynamically and, contrariwise, you can call Win32 GUI APIs from a console application.即使使用此选项,您也可以显式创建控制台窗口,如果您的应用程序需要动态的,相反,您可以从控制台应用程序调用 Win32 GUI API。

In Code::Blocks 20.03 (uses the MinGW-W64 gcc compiler project) the project target ( bin/Release ) compiles with -mwindows and the project target ( bin/debug ) compiles without -mwindows.在 Code::Blocks 20.03(使用 MinGW-W64 gcc 编译器项目)中,项目目标( bin/Release )使用 -mwindows 编译,项目目标( bin/debug )在没有 -mwindows 的情况下编译。 The debug target not only has debugging information in the executable, but it runs with the console window exposed in the background.调试目标不仅在可执行文件中包含调试信息,而且在后台公开的控制台窗口中运行。 This is 'highly' useful for debugging, since your app can write to the console debugging messages while your gui app is processing... like an active debugging log.这对于调试“非常”有用,因为您的应用程序可以在您的 gui 应用程序处理时写入控制台调试消息......就像一个活动的调试日志。 Obviously the console is ugly for release targets.显然,控制台对于发布目标来说是丑陋的。 In Code::Blocks the switch -mwindows is set indirectly in the Project properties under the 'build targets' the bin/debug build target is specified as console app, while the bin/release target is specified as gui app.在 Code::Blocks 中,开关 -mwindows 在“构建目标”下的项目属性中间接设置,bin/debug 构建目标指定为控制台应用程序,而 bin/release 目标指定为 gui app。
Back in the day (maybe eight years ago) there was a catch-22;回到当天(可能是八年前)有一个 catch-22; -mwindows was necessary to link the Win32 api (but no console). -mwindows 需要链接 Win32 api(但没有控制台)。 If you wanted a console AND the Win32 api it didn't work easily;如果你想要一个控制台和 Win32 api,它就不容易工作; fortunately this is not an issue today... you can mix and match.幸运的是,今天这不是问题……您可以混合搭配。 I generally build my release targets without the console;我通常在没有控制台的情况下构建我的发布目标; and I build the debug targets with the console, and I use the console for debugging copiously.我使用控制台构建调试目标,并使用控制台进行大量调试。 marcus马库斯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM