*BSD News Article 9737


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA6394 ; Sat, 09 Jan 93 02:06:33 EST
Path: sserve!manuel.anu.edu.au!munnari.oz.au!uunet!pipex!bnr.co.uk!uknet!edcastle!aiai!richard
From: richard@aiai.ed.ac.uk (Richard Tobin)
Newsgroups: comp.unix.bsd
Subject: Re: [386bsd] Strange behavior of the system.
Message-ID: <8144@skye.ed.ac.uk>
Date: 11 Jan 93 15:21:28 GMT
References: <3871@tansei1.tansei.cc.u-tokyo.ac.jp>
Sender: news@aiai.ed.ac.uk
Organization: HCRC, University of Edinburgh
Lines: 39

In article <3871@tansei1.tansei.cc.u-tokyo.ac.jp> mhiroshi@tansei.cc.u-tokyo.ac.jp (H. Murakami) writes:
>I encountered a unbelieavable behavior of the system now.
>If I linked the object files using gcc2 then the executable
>outputs just two warning.
>However, if I make the object archive first, and then
>link is made using the gcc2 for the object and the library,
>the result is different!

>How this can be possible????

It would help if you told us more about your program.

A possible explanation is this:

Object files and libraries are processed sequentially by the linker.
Object files are always linked in.  Modules from libraries are only
linked in if they define a symbol that is (at the time the library
is processed) referenced and undefined.

Suppose your program calls a function in the standard library (say
printf).  This library function calls another library function (say
vfprintf).  If you link your program with a .o file defining vfprintf,
that version of vfprintf will be used, and the one in the standard
library ignored.  On the other hand, if you link with a library that
defines vfprintf (but not printf), the linker will not use your
vfprintf because it isn't referenced in your program.  When it comes
to process libc.a, it will link in printf, which will result in an
undefined reference to vfprintf.  It therefore links in the version of
vfprintf from libc.a.

Libraries are not just like a big object file.  If that's what you
want then combine your .o files into one using "ld -r" rather than
"ar".

-- Richard
-- 
Richard Tobin,
Human Communication Research Centre,                       R.Tobin@ed.ac.uk
Edinburgh University.