Re: About libraries and headers



On 9 Apr 2005 08:36:16 -0700, tsoukase@xxxxxxxxx wrote:

>
>Hello,
>
>two questions:
>1) Why is a library a collection of compiled source-files
>while each header-file is a single source? Would it be more
>efficient if they were both either compiled or not?
>Could a "header-library" exist?
>2) Why do libraries have extensions .a and .so and
>modules .o, which should be reserved for cc -c output?
>Would it be better: module.m, lib.sl, lib.dl or something
>alike?
>Are these forms an inheritance from C's old-time or do
>they provide a specific functionality?
>
>Evangelos Tsoukas

You are assuming that the contents of a header file are closely
related to the contents of a library. The standard header files
describe the "user interface" to the standard functions (through the
use of function prototypes or macros), declare some standard types
(like FILE and size_t using typedef or macros), and provide access to
standard features (such as errno and stdin, commonly by macros). They
do not define how the standard functions perform their respective
tasks. For those systems that provide this, the source is usually
contained in a separate set of files which the user could use to
rebuild the functions. It is these separate files, not the headers,
which are used to build the libraries.

Header files, if they are even files at all, are used by the compiler.
Library files are used by the linker.

The contents of the standard headers are defined by the standard. The
organization of library files is an implementation detail about which
the standard says only that they exist.

For all the standard headers, compiling them would not generate any
executable code. They basically consist only of declarations and
preprocessing directives, no object definitions and no function
definitions. Try compiling a source file like
/* begin of file */
#include <stdio.h>
/* end of file */

While I don't know of any implementation to do so, there is no reason
that each library could not be the result of compiling a single source
file, though obviously not a header. Most would call this an object
file since the term library is usually used to denote a collection of
object files.


<<Remove the del for email>>
.



Relevant Pages

  • Re: bool & stdbool.h
    ... libraries. ... "library", it is a header. ... Dinkumware http://dinkumware.com/manuals/reader.aspx?lib=cpp which lists the ... Standard C library. ...
    (comp.lang.c.moderated)
  • Re: C++ compiler errors - problems with developer Tools?
    ... which happily runs on Ubuntu. ... on compiling I get ... part of the standard gnu C library. ... that header defines type T ...
    (comp.sys.mac.programmer.help)
  • Re: help!g++ compiling failed when application ported from RH 7.3 to FC3
    ... > successfully in Redhat but failed under fedora.I found the system header ... I copied from Redhat all ... If you are compiling with gcc-3.4, you must use the gcc-3.4 system ... of how strictly the compiler enforces standard langauge constructs. ...
    (Fedora)
  • Re: gcc questions
    ... First, compiling your code, and second, linking ... libraries, even very standard ones like the math library. ... There's actually no difference between the -l flag and giving the full path ...
    (Fedora)
  • Re: bool & stdbool.h
    ... "Available in the C99 standard is the 'stdbool.h' file, ... 'bool', which is an alias for the '_Bool' data type, ... libraries. ... "library", it is a header. ...
    (comp.lang.c.moderated)

Loading