我不想控制台出现时,我运行c ++程序 [英] I dont want console to appear when i run c++ program
问题描述
我想编写一个c ++程序,编译和链接.cpp给出.exe文件。如果我双击并执行它控制台打开和关闭。我不想让那个控制台出现。请帮助。
I want to write one c++ program, compiling and linking .cpp gives .exe file. if i double click on that and execute it a console gets opened and closed. I don't want that console to appear at all. Please Help.
推荐答案
Windows程序有两种方式生成控制台窗口:
There are two ways for a Windows program to produce a console window:
-
程序被链接为控制台子系统exe,这是一个要求Windows总是提供相关控制台窗口的请求。
The program is linked as a console subsystem exe, which is a request to Windows to always provide an associated console window.
程序的代码本身创建了控制台窗口。
The program's code itself creates a console window.
子系统是最可能的。
使用MinGW g ++编译器只需添加选项
With the MinGW g++ compiler just add the option
-mwindows
使用Visual C ++编译器,命令行,添加选项
With the Visual C++ compiler, if you're compiling from the command line, add the options
/link /subsystem:windows /entry:mainCRTStartup
如果您使用Visual Studio ,将子系统更改为Windows并将链接器选项中的入口点更改为 mainCRTStartup
。
If you're using Visual Studio, change the subsystem to windows and change the entry point to mainCRTStartup
in the linker options.
使用Microsoft的编译器,只需链接一个包含一个 WinMain
函数的模块就更容易了,它本身是一个非标准的启动函数,并且违反C ++标准调用普通标准 main
。这是因为与GUI子系统(子系统窗口)Microsoft的编译器,而不是例如。 g ++,默认不识别标准 main
。它只是一个微软的事情(可能是作为供应商锁定的东西开始)。
With Microsoft's compiler it can be easier to just link with a module that contains a WinMain
function that itself is a non-standard startup function, and that in violation of the C++ standard calls the ordinary standard main
. That's because with GUI subsystem (subsystem "windows") Microsoft's compiler, as opposed to e.g. g++, does not by default recognize a standard main
. It is simply a Microsoft thing (presumably it started as a vendor lock-in thing).
这篇关于我不想控制台出现时,我运行c ++程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!