Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: Notesfiles $Revision: 1.7.0.8 $; site ccvaxa
Path: utzoo!watmath!clyde!cbosgd!ihnp4!inuxc!pur-ee!uiucdcs!ccvaxa!feldman
From: feldman@ccvaxa.UUCP
Newsgroups: net.unix
Subject: Re: using libraries with ld (1)
Message-ID: <1900008@ccvaxa>
Date: Wed, 14-Aug-85 13:04:00 EDT
Article-I.D.: ccvaxa.1900008
Posted: Wed Aug 14 13:04:00 1985
Date-Received: Sun, 18-Aug-85 04:39:19 EDT
References: <240@cmu-cs-h.ARPA>
Lines: 32
Nf-ID: #R:cmu-cs-h.ARPA:-24000:ccvaxa:1900008:000:1491
Nf-From: ccvaxa.UUCP!feldman    Aug 14 12:04:00 1985


[]
>> Some versions of "ld" support the "-Llibpath" option to specify an
>> additional directory to search for libraries.
>> 
>> You can always just name the library in the "ld" or "cc" command:
>> 	cc -o myprog myprog.o mysub.o mylib.a -lm -lplot

> I was under the impression that libraries specified in the way that mylib.a
> is have the entire library linked in rather than just those routines which
> are needed because of undefined identifiers.  Does anyone know if this is
> actually the case?

File arguments to BSD derived versions of ld are examined for a "magic number";
if the file is an a.out file, it is loaded.  If it is a ar archive file things
are more complicated.  In general, the ar file has been ranlib'ed since it
was last ar'ed.  In this case, only what is needed gets loaded.  Otherwise,
ld complains about the library being out of date or not having been ranlib'ed
and makes a single pass through the library, which often leaves undefineds.

Ld pays no attention to filename suffixes, so for example, -lg (/usr/lib/libg.a)
is really a .o file and gets loaded no matter what.

Ld will also use the size of a common symbol (undefined external with non-zero
value) from a library member WITHOUT loading library member if that member
resolves no other undefined references.  This can cause the resulting a.out
file to be unexpectedly big.  I'm waiting to see if this is fixed in 4.3.

Mike Feldman
Gould Computer Systems
Urbana, IL
{ihnp4|pur-ee}!uiucdcs!ccvaxa!feldman