www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/22/10:04:50

From: kagel AT quasar DOT bloomberg DOT com
Date: Mon, 22 Jul 1996 09:56:42 -0400
Message-Id: <9607221356.AA02960@quasar.bloomberg.com >
To: mharris AT blackwidow DOT saultc DOT on DOT ca
Cc: brucef AT central DOT co DOT nz, djgpp AT delorie DOT com
In-Reply-To: <Pine.LNX.3.91.960721193703.10120A-100000@blackwidow.saultc.on.ca> (mharris@blackwidow.saultc.on.ca)
Subject: Re: How do I create my own libraries ?
Reply-To: kagel AT dg1 DOT bloomberg DOT com

   Date: Sun, 21 Jul 1996 19:43:38 -0400 (EDT)
   From: "Mike A. Harris" <mharris AT blackwidow DOT saultc DOT on DOT ca>

   On Sun, 21 Jul 1996, Eli Zaretskii wrote:

   > On Sat, 20 Jul 1996, Bruce Foley wrote:
   > 
   > > BTW, I was wondering, when a program uses a function
   > > from a library, does the whole library get linked, or just
   > > the function you are calling?
   > 
   > Only the function(s) you call are linked.  Otherwise, every DJGPP program 
   > will be at least the size of libc.a, which is 530KBytes.

   This poses an interesting question.  In the past, when coding libraries
   for Borland C 3.1, I put all of the functions in a single .c module.  Then
   put the resulting obj into a .lib.  After discussing this on the FIDO C_ECHO
   I found out that, at least with Borland, when you put more than one function
   into a C source module, and then put the module into a lib, or even just use
   the obj, that when you include that lib or obj into a program, ALL functions
   are linked into the code wether or not they are actually used in the code.

   This posed an interesting learning experience.  So ever since then, when
   coding libs, I've used one function per module.  This prevents unneeded
   code from bloating executables.

   Is this also true of DJGPP?  What about other compilers?  Should one always
   code LIBs as one function per module source files?

Yes, with the usual disclaimer about using absolutes.  The DJGPP libraries are
coded this way.  There are linkers out there which can extract a single
function from a library module, but, they are rare, ld is not one of these.

Generally, put multiple functions into a single module, read "source file", if
they are so interlinked, or intrinsically related, that a user will either
always need to call all of the functions himself anyway or by calling one may
cause all of the others to be called internally anyway.  Since in either of
these cases all of the functions will be pulled in by the linker anyway,
putting them into a single module will speed link times by allowing several
symbols to be resolved when the first symbol causes the module to be extracted
from the library thereby saving several subsequent searches.

-- 
Art S. Kagel, kagel AT quasar DOT bloomberg DOT com

A proverb is no proverb to you 'till life has illustrated it.  -- John Keats

- Raw text -


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