Showing posts with label c header files. Show all posts
Showing posts with label c header files. Show all posts

Saturday, July 24, 2010

Header files and Libraries in c

C Header Files

A header file contains declarations, macro definitions that can be shared between several source files. one can include a header file in their program with the preprocessor tag #include.

System hearder files are predefined. One can include them in their program to provide the definitions and declarations need to invoke system calls and libraries.

#include

One can write their own header files which contains decarations shared between source files of their program.

#include "myheader.h"

C Libraries

GNU C standard library contains several header files which are used to implement common operations. For an example, the header file stdio.h declares facilities for performing input and output, and the header file string.h declares string processing utilities.

Library typically contains previously compiled codes. One can create their own library .Compilation process is shown below for creating a library.

Commands for creating the object file

cc -c mylibrary.c

Commands for creating the library

ar -q mylibrary.a mylibrary.o

using the created library with other source files

cc main.c mylibrary.a

note that main.c uses the definitions, declarations contain in mylibarary.