public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
To: "'Fredrik Eldh'" <lazermasken@hotmail.com>
Cc: "'GNU-Win32'" <gnu-win32@cygnus.com>
Subject: RE: Linking problems
Date: Wed, 17 Sep 1997 21:11:00 -0000	[thread overview]
Message-ID: <01BCC432.7FDB0400@gbird0> (raw)

Fredrik Eldh[SMTP:lazermasken@hotmail.com] wrote:
>I'm a newbie when it comes to Gnu-Win32 and I'm having trouble when I 
>try to link any Win32 program. The linker says I have 'undefined 
>references' to all the Win32 API functions. I use the following command 
>line to compile and link: "gcc program.c".
>
>Now, please don't tell me to go look this up in an FAQ or something, 
>I've already done that and it didn't make me wiser.

It's pretty simple actually, and it should be a FAQ. GNU-Win32 requires
that you explicitly link the import libraries for whatever Win32 API
functions that you are going to use, with the exception of kernel32,
which is linked automatically (because the startup and/or built-in code
uses it). For example, to use graphics functions (GDI) you must link
with gdi32 like this:

  gcc -o foo.exe foo.o bar.o -lgdi32

or (compiling and linking in one step):

  gcc -o foo.exe foo.c bar.c -lgdi32

The regular Cygnus setup allows you to use the option -mwindows on
the command line to include a set of the basic libraries (and also
make your program a GUI program instead of a console program),
including user32, gdi32 and, IIRC, comdlg32.

A few notes:

 - Do not ever include -lkernel32 on your link line (unless you are
   invoking ld directly, in which case I share your pain).

 - Do not include the same import library twice on your link line.

 - Put import libraries last on your link line, or at least after
   all the object files and static libraries that reference them.

The first two are related to problems the linker has currently when
import libraries are referenced twice. Tables get messed up and
programs crash randomly. The last point has to do with the fact that
GCC processes the files listed on the command line in sequence and
will only resolve references to libraries if they are given after
the file that makes the reference.

Anyway, hope that helped.

Colin.

PS. Actually GCC is not being any different from MSVC or other
    Win32 compilers about this. Just open up the build options
    dialog and look for the list of libraries to link. By default
    you'll find a whole mess of import libraries including all
    the ones I mentioned above (at least the last time I looked).

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

             reply	other threads:[~1997-09-17 21:11 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-17 21:11 Colin Peters [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-02-01 17:39 Sean LeBlanc
2004-02-01 23:17 ` Larry Hall
2004-02-02  0:32   ` Sean LeBlanc
2004-02-02  1:12     ` Larry Hall
2000-01-27 14:16 Earnie Boyd
2000-01-27  9:00 Earnie Boyd
2000-01-27  9:58 ` Andre Oliveira da Costa
2000-01-26 15:05 Earnie Boyd
2000-01-27  5:35 ` Andre Oliveira da Costa
2000-01-26  4:31 Andre Oliveira da Costa
2000-01-26 14:35 ` Andre Oliveira da Costa
1999-08-10  5:28 LInking problems MR. S.CHANDER
1999-08-11 11:27 ` Mumit Khan
1999-08-12  7:52   ` MR. S.CHANDER
1999-08-12  8:08     ` Mumit Khan
1999-08-13  6:03       ` MR. S.CHANDER
1999-08-31 23:49         ` MR. S.CHANDER
1999-08-31 23:49       ` Mumit Khan
1999-08-31 23:49     ` MR. S.CHANDER
1999-08-31 23:49   ` Mumit Khan
1999-08-31 23:49 ` MR. S.CHANDER
1998-07-23  8:33 Linking problems Aaron Schweiger
1998-07-24  0:25 ` Mumit Khan
1997-09-18  6:41 Ernest Clayton Cordell, Jr.
1997-09-17  4:35 Fredrik Eldh
1997-09-17 12:30 ` Mikey
1997-07-07  7:09 Jon Thackray
1997-07-07 12:07 ` Jon Thackray
1997-06-30  5:58 linking problems Wei Ku
1997-06-27  1:29 Berenice LOPEZ
1997-06-17  7:47 Linking problems Manmathan Muthukumarapillai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01BCC432.7FDB0400@gbird0 \
    --to=colin@bird.fu.is.saga-u.ac.jp \
    --cc=gnu-win32@cygnus.com \
    --cc=lazermasken@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).