Re: How do linkers work? (Eric Meijer)
21 Oct 1999 14:19:03 -0400

          From comp.compilers

Related articles
How do linkers work? (Dave Wilson) (1999-10-21)
Re: How do linkers work? (1999-10-21)
Re: How do linkers work? (Alan Donovan) (1999-10-21)
Re: How do linkers work? (1999-10-21)
Re: How do linkers work? (1999-10-21)
Re: How do linkers work? (1999-10-27)
| List of all articles for this month |

From: (Eric Meijer)
Newsgroups: comp.unix.programmer,comp.compilers
Followup-To: comp.unix.programmer,comp.compilers
Date: 21 Oct 1999 14:19:03 -0400
Organization: Eindhoven University of Technology, The Netherlands
References: 99-10-097
Keywords: linker

: Consider a static library containing several functions. Some of the
: functions in the library (e.g. Fred()) are contained entirely within
: the library, whereas others (e.g. Bill()) call functions outside the
: library.
: Now it makes sense that programs that use the library and call Bill() need
: to defined the functions that Bill() calls before a successful link.
: However, much to my dismay, programs that only use Fred() from the
: library also need to define the functions that Bill() needs __even
: though this code is never executed!__.
: Forgive me if I'm displaying a certain ignorance about current linker
: technology, but I thought linkers could figure out certain things like
: which functions will never get called and leave them out.

Static libraries contain object files. With `nm' you can see what
object files are there, and what functions they contain. The linker
always links complete object files, so that if Fred() and Bill() are
in the same object file, and you link Fred(), you also link Bill().
Object files in libraries that contain no functions that are used are
not linked.


  E.L. Meijer (
  Eindhoven Univ. of Technology
  Lab. for Catalysis and Inorg. Chem. (SKA)
[Actually, static linked shared libraries generally glom the entire library
into what is in effect a single object file. That's probably what's going
on here. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.