12

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

Daniel
  • 30,896
  • 18
  • 85
  • 139
geek
  • 2,677
  • 4
  • 23
  • 21
  • A related thread: https://stackoverflow.com/questions/11716350/effects-of-switching-between-subsystemconsole-to-subsystemwindows-in-a-dll – smwikipedia Dec 11 '20 at 05:11

4 Answers4

17

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

ks1322
  • 33,961
  • 14
  • 109
  • 164
  • 13
    SUBSYSTEM:WINDOWS isn't necessarily for GUI apps. Just for apps without a console. Think server apps, services that run headless. – David Heffernan Sep 06 '11 at 12:28
  • 3
    If targeting Windows XP from MSVC 2013 command line, you may need /SUBSYSTEM:WINDOWS,5.1 (or :CONSOLE,5.1) – Tim Ruddick Mar 25 '14 at 20:40
  • 1
    @DavidHeffernan SUBSYSTEM:WINDOWS isn't necessarily for GUI apps either. It can call AllocConsole() if it needs a console. What happens is that for /SUBSYSTEM:CONSOLE console setup (and I think stdout/stdin setup) happen automatically. So /SUBSYSTEM:WINDOWS is for apps without an **automatically allocated** console – nponeccop May 08 '20 at 14:39
  • 1
    A DLL without specifying `/SUBSYSTEM` (i.e. select NOT SET in Visual Studio) still has the SUBSYSTEM field set to `Windows GUI`. Check: https://stackoverflow.com/questions/11716350/effects-of-switching-between-subsystemconsole-to-subsystemwindows-in-a-dll – smwikipedia Dec 11 '20 at 05:15
8

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.

Alex F
  • 42,307
  • 41
  • 144
  • 212
  • 1
    The default entry point for `/subsystem:console` is `[w]mainCRTStartup`, for `/subsystem:windows` it's `[w]WinMainCRTStartup`. It just so happens that the CRT implements those two functions and these implementations call `main` and `WinMain`, respectively. Thus, `main` and `WinMain` become the entry point for the programmer with which the linker as (almost) nothing to do. https://learn.microsoft.com/en-us/cpp/build/reference/entry-entry-point-symbol?view=vs-2017 – René Nyffenegger Mar 13 '19 at 05:23
  • Seems somewhat contrary to what the official documentation says: "The choice of subsystem affects the entry point symbol (or entry point function) that the linker will select". – Sam Sep 23 '20 at 15:17
  • @Sam There are actually several values for `/SUBSYSTEM`. Choosing different one will cause the linker to search for different symbols. – smwikipedia Dec 11 '20 at 05:17
4

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.

pcunite
  • 1,197
  • 15
  • 23
3

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

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 1
    This is not entirely true. E.g. a process with `/SUBSYSTEM:WINDOWS` can have a console if it calls `AllocConsole()` – nponeccop May 08 '20 at 14:33