Discussion:
gcc -Wl,--subsystem,windows -mwindows options
Glenn A. Carlson, P.E.
2004-01-24 16:56:34 UTC
Permalink
-Wl,--subsystem,windows -mwindows

What exactly do these gcc options do? Are they preprocessor, compiler, or
linker options? Sometimes I only need -windows; sometimes I need both. How
do I know when I will need both or just -mwindows?

I know they are needed when creating MS Windows apps, but I'm not clear on
what they are doing. Up to now, I've included these options rather
mindlessly in my MS Windows apps, but I'd like to know more about them.

The gcc documentation lists several "Hardware Models and Configurations" -m
options, but -mwindows is not listed.

The gcc documentation also states -Wl,option will "Pass option as an option
to the linker. If option contains commas, it is split into multiple options
at the commas," but I can't find any information on what the option
"--subsystem,windows" does.

Thanks for the information.

Glenn Carlson
Ian Lance Taylor
2004-01-24 19:18:42 UTC
Permalink
Post by Glenn A. Carlson, P.E.
-Wl,--subsystem,windows -mwindows
What exactly do these gcc options do? Are they preprocessor, compiler, or
linker options? Sometimes I only need -windows; sometimes I need both. How
do I know when I will need both or just -mwindows?
As you discovered, -Wl,--subsystem,windows passes `--subsystem
windows' to the linker. -mwindows is a compiler option; however, it's
only affect is on the options which the compiler passes to the
linker.

For the linker, --subsystem is documented in the linker manual as
follows:

@kindex --subsystem
@item --subsystem @var{which}
@itemx --subsystem @var{which}:@var{major}
@itemx --subsystem @var{which}:@var{major}***@var{minor}
Specifies the subsystem under which your program will execute. The
legal values for @var{which} are @code{native}, @code{windows},
@code{console}, and @code{posix}. You may optionally set the
subsystem version also.
[This option is specific to the i386 PE targeted port of the linker]

Admittedly that is not particularly informative. As far as I can see
from the code, the effect is to set the entry point to
WinMainCRTStartup, and to set the symbol __subsystem__ to 2.
Presumably this is something the Microsoft linker also does.

For the compiler, from the source code, the effect of -mwindows is to
add -lgdi32 and -lcomdlg32 to the list of default libraries (the uwin
target also adds -luser32), and to pass --subsystem windows to the
linker.

So it seems that if you use -mwindows you shouldn't need to also use
-Wl,--subsystem,windows, since that will happen anyhow, at least for
the cygwin, mingw32, and uwin targets.

Ian

Loading...