delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/19/05:04:35

From: eighner AT io DOT com (Lars Eighner)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: difference between libraries and headers
Date: Thu, 18 Nov 1999 23:16:17 -0600
Organization: Lars Eighner, Author
Lines: 56
Message-ID: <h0NN4AwZqU7D092yn@io.com>
References: <80vhq4$kvc AT hermes DOT acs DOT unt DOT edu>
NNTP-Posting-Host: dillinger.io.com
Mime-Version: 1.0
X-Trace: hiram.io.com 943001951 9720 199.170.88.20 (19 Nov 1999 08:59:11 GMT)
X-Complaints-To: abuse AT io DOT com
NNTP-Posting-Date: 19 Nov 1999 08:59:11 GMT
X-Newsreader: Yarn 0.92 with YES 0.22
X-ISP: Illuminati Online
X-Revision: 1
Originator: eighner AT dillinger-2 DOT io DOT com (Lars Eighner)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

In our last episode <80vhq4$kvc AT hermes DOT acs DOT unt DOT edu>,
the lovely and talented "Morpheus" <hall AT cs DOT unt DOT edu>
broadcast on comp.os.msdos.djgpp:

|I know the difference between a library file and a header file, but can
|someone tell me the particulars involved -- the differences between
|compiling your program with included headers and including a library on the
|prompt? I know the header files on the include path don't contain a full
|implementation of their functions/classes, so where is this implementation?
|If it's in the library files, how does the compiler know which library to
|get without specifying it at the prompt? If compiling with libraries and
|headers are independent things, then what is the advantage of compiling with
|library files?


Header files should contain declarations for your (public) library 
functions and nothing executable whatsoever.  You ought to (in C++ 
you must) declare functions before you use them.  It is more convenient
to have the header files to #include (and also for you to look at
in case you forget exactly how a call goes).  You could, I suppose,
type the declarations into your program.  That wouldn't be much fun.

The header files are headers for your program.  They are just there
for your convenience.  Not only do they not contain the full
implementation of the library functions, they shouldn't.  They should
just contain the declarations necessary for the user interface
("user" here means you -- the user of the library functions -- not the 
user of your programs).

The implementation is in object code (binary) archieved in the libraries.
A library file generally looks like Lib*.a .  You can find the source
code for the GNU libraries, of course.  But in a "real world"
programming environment, you would probably have a number of
proprietary libraries -- and you wouldn't get the source code for
them.  The whole point of object-oriented programming is that
the source code for libraries is none of your business.  

Your program will not compile at all without the header files
(unless you do type in all of the declarations yourself).  They
will not compile into executables unless the linker can find
the library files.  Fortunately, in djgpp "out of the box" the
linker knows where to look for the usual suspects, so it is all
very seamless to you when you are doing "Hello, world!"  If you
are doing a very involved project, however, you probably will
have your own library or libraries.  Then you'll have to be
concerned with putting your libraries where the linker can find
them or telling the linker where your libraries are.



-- 
          Lars Eighner  700 Hearn #101 Austin TX 78703 eighner AT io DOT com
      (512) 474-1920 (FAX answers 6th ring) http://www.io.com/%7Eeighner/
              bookstore: http://www.io.com/%7Eeighner/bookstore/
  "Have you ever dated somebody because you were too lazy to commit suicide?"

- Raw text -


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