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


Jason Zions[SMTP:jazz@softway.com] wrote:
>> You have to explicitly link in any Win32 API libraries you
>> need functions from (except for kernel32, which you should never explicitly
>> link).
>
>I'm curious about this. Why should one never explicitly link kernel32?

As someone else mentioned, because it is automatically linked in. Of course,
that isn't actually a good reason to not explicitly link a library (except
if you are concerned with making your links go faster). However, the linker
right now has problems if you link the same import library more than once.
The whole import table gets messed up and your programs will crash under
mysterious circumstances. Until this gets fixed the workaround is to be
very, very careful and make sure you never link the same import library
more than once. Since kernel32 is automatically linked, you should never
put it on your link command line.

This is a (reasonably) well known gotcha (at least for "old timers" on
the list <creak> <creak>). Lots of programmers, including myself, have
been caught running a seemingly innocuous command like this:

  gcc -o hello.exe hello.o -luser32 -lgdi32 -lkernel32

It links fine, but crashes quite spectacularly. Worse is when it doesn't
crash right away, but only when you call some API function or other. Bleah!

Hope that makes it all clear,
Colin.

-- Colin Peters - Saga Univ. Dept. of Information Science
-- colin@bird.fu.is.saga-u.ac.jp - finger for PGP public key
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

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