delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/03/13:48:26

Date: Thu, 3 Jul 1997 10:42:10 -0700 (PDT)
Message-Id: <199707031742.KAA02459@adit.ap.net>
Mime-Version: 1.0
To: djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: What are libraries?

>PAOLO PISELLI M Z wrote:
>> 
>> I have been programming with DJGPP for a little while and
>> want to start building a library out of some of my object files.
>> As I am unfamiliar with libraries, I have a few questions which
>> I hoped someone could answer:
>> 
>> 1) What exactly _is_ a library?  Is it a list of object files?
>> does it have a header file?
>Basically it is some object files dumped into one file and a
>header prepended. The idea is that most OSs have large overhead
>opening many small files, so it is faster to open one big
>file and gather the information in one file. 

Also speaking of header files, you usually want to make a .h file with
declarations of all your functions and extern variables, then #include it in
each source file that uses your library. This avoids many ugly type mismatch
problems.

Also, here's one subtle point of libraries that baffled me for a while.
When you link with a library, what happens is this:
- Linker looks through header to find if any unresolved symbols(*) are
defined there.
- Linker extracts each .o file in the library containing symbols it needs.
- Linker links with that .o file as normal.

This means that your definitions can override that of the library. You will
not get a redefined symbol error unless a symbol you have defined is in the
same .o member as another symbol that's unresolved.

Moral of the story: Break down library members as much as possible. Usually
recommended is one source/object file per function.

(*) symbol = function/variable name


Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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