gcc -Wl,--subsystem,windows -mwindows options

Ian Lance Taylor ian@wasabisystems.com
Sat Jan 24 19:18:00 GMT 2004


"Glenn A. Carlson, P.E." <gcarlson@xannah.org> writes:

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



More information about the Gcc-help mailing list