Compiling Windows GUI Application With MinGW Without Command Prompt
bamccaig

I want the resulting program to launch without the command prompt window... I didn't word the topic very well.

I tried searching the forums and came up empty... I would have thought that this question would have come up numerous times... Anyway, I'm trying to compile this tutorial program so that just the main window opens (and not the command prompt window). I compiled using MinGW:

gcc -O2 simple_window.c -o simple_window.exe

The result is that a command prompt window opens as well...

http://www.allegro.cc/files/attachment/594337

I've gathered that something needs to be specified in the build process to indicate that no command prompt window is desired (which I expect Visual Studio would do for you when creating a Windows GUI application), but I've been unsuccessful in determining what... :-/

Myrdos

I seem to remember that there's an option in Dev-Cpp for this, you select a Win program instead of a Console program when you first create a new project. It then dumps some code into a main source file to get you started.

Even if you aren't using Dev-Cpp, it may be worth taking a look. You might be able to just copy+paste that code into yours.

Mika Halttunen
Quote:

I've gathered that something needs to be specified in the build process to indicate that no command prompt window is desired (which I expect Visual Studio would do for you when creating a Windows GUI application), but I've been unsuccessful in determining what...

-mwindow or -mwindows (can't remember which :))
I think it's the first.

amber

No, it's the second. :)
Do something like:
gcc -mwindows -o whatever.exe whatever.c -lalleg
and you should be good. :)

Thomas Fjellstrom

-mwindows is depreciated, you want -Wl,-subsystem,windows

bamccaig

Thanks, guys. :D So can anybody explain what they do and perhaps the difference between -mwindows and -Wl,-subsystem,windows? :-/ An MSDN reference would suffice as well since I can't seem to find anything related to it from Microsoft...

ReyBrujo

MinGW is not a Microsoft-related product, so you won't find information about that there. In old versions of the MinGW compiler, you used -mwindows to tell the compiler you want a native Win32 application without console output (every Windows application has an associated console window associated for stdin, stdout and stderr, to keep compatibility with old code ported to Windows that requires a place to output messages). In newer versions, the switch was changed to -Wl,-subsystem,windows. They are both the same, but since -mwindows is deprecated, the switch may be removed from the compiler in the future.

Evert
Quote:

So can anybody explain what they do and perhaps the difference between -mwindows and -Wl,-subsystem,windows? :-/

Dunno. -mwindows might stop working at some point (it's been deprecated for years), other than that I don't know what practical differences there are or might be.
Just do as they tell you and switch to using the new flags and you'll be fine. ;)

Quote:

An MSDN reference would suffice as well since I can't seem to find anything related to it from Microsoft...

You're looking for a GNU compiler option on Microsoft's website?

bamccaig
ReyBrujo said:

MinGW is not a Microsoft-related product, so you won't find information about that there.

Evert said:

You're looking for a GNU compiler option on Microsoft's website?

I didn't realize that it was specific to the compiler... :-[ So then what do you do with the Visual Studio C/C++ compiler(s) to get rid of the command window?

** EDIT **

It helps a lot to know that there are compiler specific instructions. :) Why though do they still use -mwindows and -mconsole... :-/

Following are the results of my search of an explanation for -Wl,-subsystem,windows...

-Wl,option:
(option in the above examples is -subsystem,windows which is split into -subsystem windows)

     Pass option as an option to the linker. If option contains commas, it is
     split into multiple options at the commas.*

-subsystem which:
(which in the above example is windows)

     Specifies the subsystem under which your program will execute. The legal
     values for which are native, windows, console, posix, and xbox. You may
     optionally set the subsystem version also. Numeric values are also
     accepted for which. [This option is specific to the i386 PE targeted port
     of the linker]**

It was also helpful to search the output from MinGW's gcc -v --help for -mwindows.

* GCC Link Options ** ld Options

Arthur Kalliokoski

I believe -mwindows includes -luser32 and -lkernel32 (?) automatically, as far as Winduhs creating a console window along with your "real" window, there's some sort of flag in the executable header that specifies if it's a console app or not.
[EDIT}
http://support.microsoft.com/kb/90493 for console flag

bamccaig
Arthur Kalliokoski said:

I believe -mwindows includes -luser32 and -lkernel32 (?) automatically, as far as Winduhs creating a console window along with your "real" window, there's some sort of flag in the executable header that specifies if it's a console app or not.
[EDIT}
http://support.microsoft.com/kb/90493 for console flag

Thanks, that's interesting to know. So I guess in theory you could even write a program that would alter the subsystem/UI flags in other executables... :)

Unfortunately, it's too late for cookies... I knew this would happen!

BAF
Quote:

So then what do you do with the Visual Studio C/C++ compiler(s) to get rid of the command window?

Change the application type from Console Application to Windows Application.

CGamesPlay

Also known as the subsystem in the project settings.

bamccaig
BAF said:

Change the application type from Console Application to Windows Application.

CGamesPlay said:

Also known as the subsystem in the project settings.

I'm sure I can figure it out in Visual Studio. I'm speaking more in terms of using the compiler/linker directly from the command line (albeit, I probably won't ever do that with VC++).

ReyBrujo

(From the Allegro makefile) For cl.exe, use -subsystem:console or -subsystem:windows

bamccaig
ReyBrujo said:

(From the Allegro makefile) For cl.exe, use -subsystem:console or -subsystem:windows

Thanks. :)

Thread #594895. Printed from Allegro.cc