delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/08/10:09:41

Date: Wed, 8 May 1996 17:01:55 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Martynas <martynas DOT kunigelis AT vm DOT ktu DOT lt>
Cc: DJGPP mailing list <djgpp AT delorie DOT com>
Subject: Re: libraries
In-Reply-To: <199605081048.GAA11450@delorie.com>
Message-Id: <Pine.SUN.3.91.960508164242.18314A-100000@is>
Mime-Version: 1.0

On Wed, 8 May 1996, Martynas wrote:

> What is the order ld looks for object files through libraries. I mean, why
> does ld take math functions from libm, while they are also found in libc?

`ld' searches the files (both objects and libraries) only once, in the
order they are listed on the command line.  When gcc creates the command
line it passes to `ld', it first mentions all the object files and
libraries from your original gcc command line (if you mentioned source
files, gcc changes their extension to .o, and -l<lib> switches are changed
to the lib<lib>.a names), then appends "libgcc.a libc.a libgcc.a".  If
your command line includes -lm, `ld' sees libm.a *before* libc.a, so by
the time it scans libc.a, the math functions are already resolved.  If
your command line doesn't include -lm, the math functions will be loaded
from libc.a.

> I could put object files with empty globbing and env-file functions to some
> library and then shorten the executables by linking with it. However, when
> I tried that trick some time ago, it didn't work. So what gives?

It should have worked.  I do this by defining such empty functions on one 
of the source files I compile, but putting them in a library should work 
just as well.  I suggest you try again and if it doesn't, post the source 
of these functions and the command line you use to link against that 
library.

You might also find a few `ld' options useful when debugging such 
problems.  The options `-t', `--verbose' and `-y SYMBOL' are the ones you 
should consider (look them up in the ld Info docs).  Gcc lets you pass 
arbitrary options to the linker by using the `-Wl,option' and
`-Xlinker option' switches (described in the gcc Info docs).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019