C static libraries
A library in C is a collection of header files, exposed for use by other programs. The library therefore consists of an interface expressed in a .h file (named the "header") and an implementation expressed in a .c file. This .c file might be precompiled or otherwise inaccessible, or it might be available to the programmer.
The format of a library varies with the operating system and compiler one is using. For example, in the Unix and Linux operating systems, a library consists of one or more object files, which consist of object code that is usually the output of a compiler if the source language is C or something similar.
There are many library functions available in C programming to help you write a good and efficient program. But, why should you use it because they work, these functions have gone through multiple rigorous testing and are easy to use. Also the functions are optimized for performance so a dedicated group of developers constantly make them better. In the process, they are able to create the most efficient code optimized for maximum performance. Libraries saves considerable development time since the general functions like printing to a screen, calculating the square root, and many more are already written. You shouldn't worry about creating them once again it saves valuable time and your code may not always be the most efficient. And finally the functions are portable with ever changing real world needs, your application is expected to work every time, everywhere and, these library functions help you in that they do the same thing on every computer . This saves time, effort and makes your program portable.
To create a static library we have to follow three simple steps.
- Compile your Library code(.c files) into an object code.
$ gcc -c *.c
- Create a Static Library from all “.o” files using command ar.
$ ar -rc libholbertonschool.a *.o
- create index for the library using ranlib command.
$ ranlib libholbertonschool.a