Subject: RE: Compiler
From: [email-masked] (Colin Peters)

29 Oct 1997 17:48:04 -0800
Message-ID: <01BCE51B.5D67E960.cygnus.gnu-win32@gbird0>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
To: "'Jason Zions'" <[email-masked]>
Cc: "'GNU-Win32'" <[email-masked]>

Jason Zions[SMTP:[email-masked]] 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
-- [email-masked] - 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
"[email-masked]" with one line of text: "help".