I dont want console to appear when i run c++ program

后端 未结 7 789
时光取名叫无心
时光取名叫无心 2021-02-07 11:24

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 consol

相关标签:
7条回答
  • 2021-02-07 12:03

    There are two ways for a Windows program to produce a console window:

    • 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.

    The first option, console subsystem, is by far most likely.

    With the MinGW g++ compiler just add the option

    -mwindows
    

    With the Visual C++ compiler, if you're compiling from the command line, add the options

    /link /subsystem:windows /entry:mainCRTStartup
    

    If you're using Visual Studio, change the subsystem to windows and change the entry point to mainCRTStartup in the linker options.

    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).

    0 讨论(0)
提交回复
热议问题