libs, Compiling…and Debugging

What´s the difference between a header file and a library ?

Header files are code.
Libraries files are compiled code.
It's the fundamental difference between "interface" and "implementation"; the interface (header) tells you how to 
call some functionality (without knowing how it works), while the implementation (library) is the actual functionality.
Note: The concept is so fundamental, because it allows you flexibility: you can have the same header for different 
libraries (i.e. the functionality is exactly called in the same way), and each library may implement the functionality 
in a different way. By keeping the same interface, you can replace the libraries without changing your code.
---
One thing that may be confusing you is that the word library can have several meanings in C++.
It could refer to a set of functions in a binary file. These can be statically linked or dynamically linked.
And can also refer to a set of included header files.
---
A library is code, compiled into a set of object files. The object files contain the compiled machine code and
the data declarations used by the code.
A header file defines the interface to a library: it tells you how to use the library correctly. 
In C/C++, a header file gives you a list of function names and how to call those functions: 
the number and types of parameters they take, the return type, the calling convention, etc. 
Header files have a lot of other stuff in them, too, but in the end, what it boils down is a set of 
rules for calling library code.
---
Header only contains the declaration, whereas libraries also contains the implementaion.
A header file describes how to call the functionality, a library contains the compiled code that implements 
this functionality.

---

A header file is generally used to define an interface or set of interfaces within an application. 
Think of a header file as something which shows the external functionality of a program while omitting the 
technical implementation details.
For example, if you were optimising a program, you would most likely modify the source (.cpp) file to improve 
the algorithm, but the header file wouldn't change, because external clients still call the methods using the 
same set of parameters and return values.

In an object-oriented language like C++, a header file generally includes the following:
- Class description and inheritance hierarchy
- Class data members and types
- Class methods

While there is nothing stopping code from being implemented in a header file, this is generally not favoured as it can 
introduce extra coupling and dependencies in the code.
In some cases (e.g. templated classes) the implementation must be defined in the header file for technical reasons.

A library is a collection of code which you want to make available to a program or group of programs. 
It includes the implementation of a particular interface or set of interfaces.
Code is defined in a library to prevent code duplication and encourage re-use. 
A library can be statically-linked (.lib) or dynamically-linked (.dll):

A statically-linked library defines a set of export symbols (which can be thought of as method definitions) 
which are then linked into the final executable (.exe) during the linking stage of the build process. 
It has the advantage of faster execution time (as the library doesn't need to be dynamically loaded), 
at the expense of a larger binary (because the methods are essentially replicated in the executable file).

A dynamically-linked library is linked during the execution of a program, rather than the linking of a program. 
It is useful when multiple programs need to re-use the same methods, and is used extensively in technologies such
as COM.

The GNU C Library
1
http://www.gnu.org/software/libc/download.html
Downloads :   http://ftp.gnu.org/gnu/glibc/ 
PDF doc    :   http://www.gnu.org/software/libc/manual/pdf/libc.pdf

 

GDB
GNU Project Debugger




.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

Leave a comment