geek
geek

Reputation: 2847

difference between Console (/SUBSYSTEM:CONSOLE) and Windows (/SUBSYSTEM:WINDOWS)

can somebody please explain difference between those two declarations in the properties of the linker in visual studio 2008( please as simple as possible, I'm new in the world of C++) thanks in advace

edit: if possible can you give me please two small programs to show an effect

Upvotes: 14

Views: 30836

Answers (5)

Valentin
Valentin

Reputation: 67

My solution in 2023 with SDL2 and VSCode, compiling with mingw32:

For the production build I use the flag -mwindows which prevents std::cout and printf from being printed anywhere.

To debug I change the flag -mwindows to -Wl,-subsystem,console to allow std::cout and printf to be printed in a console window.

Upvotes: 1

pcunite
pcunite

Reputation: 1197

See here. VS2008 automates some things for you which has lead to the confusion.

CONSOLE Win32 character-mode application. The operating system provides a console for console applications. If main or wmain is defined for native code, int main(array ^) is defined for managed code, or you build the application completely by using /clr:safe, CONSOLE is the default.

WINDOWS Application does not require a console, probably because it creates its own windows for interaction with the user. If WinMain or wWinMain is defined for native code, or WinMain(HISTANCE *, HINSTANCE *, char *, int) or wWinMain(HINSTANCE *, HINSTANCE *, wchar_t *, int) is defined for managed code, WINDOWS is the default.

Upvotes: 4

Alex F
Alex F

Reputation: 43331

CONSOLE: Console window is shown. WINDOWS - program starts without Console window.

Edited, looking at another answers. Notice that /SUBSYSTEM flag doesn't affect the program entry point. Program entry point is defined by /ENTRY linker option. Usually /SUBSYSTEM:CONSOLE has "main" entry point, and /SUBSYSTEM:WINDOWS has "WinMain" entry point. But it is possible, for example, to create GUI application with WinMain entry point and Console window.

Upvotes: 10

David Heffernan
David Heffernan

Reputation: 613592

/SUBSYSTEM:CONSOLE results in a process with a console and /SUBSYSTEM:WINDOWS does not.

Upvotes: 3

ks1322
ks1322

Reputation: 35875

/SUBSYSTEM:CONSOLE) is for console based applications. You should define main function in code.

/SUBSYSTEM:WINDOWS) is for GUI applications. You should define WinMain function.

Upvotes: 20

Related Questions