This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: EGCS-Mingw32 Win32


Paul Garceau <pgarceau@teleport.com> wrote:
> Under EGCS-Mingw32, why is it necessary to add a -l reference for
> User32 for a command such as:
>
> gcc test.c -o test.exe
>
>       in order to generate a successful link?


(Assuming test.c uses some functions from the user32 DLL.) This is because
the only Win32 API library included by default in Mingw32 is kernel32 (it's
needed by the startup code). If you are writing a program that uses other
API functions then you need to link in the API libraries explicitly.

Now, if you are writing a GUI program you can use -mwindows and you will
automatically get user32 and a few other basic Win32 API libraries. It was
done this way because GUI programs usually use the Win32 API, so it makes
sense to do the extra library linking. (Note: you can't do "gcc -o test.exe
test.c -mwindows" because the windows option will get sent to the compiler
as well as the linker, and the compiler doesn't understand it, so you have
to compile first and then link with -mwindows.)

I suppose we could just include all those libraries by default all the time,
though I don't think it makes much difference once you understand what's
going on.

Colin.

- Colin Peters - colin at fu.is.saga-u.ac.jp
- http://www.geocities.com/Tokyo/Towers/6162/index.html
- Go not to usenet for counsel, for it will say both
- 'yes' and 'no' and 'try another newsgroup'.


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]