What are the differences between static and dynamic libraries ?
A library is a collection of subroutines that allows the code of those subroutines to be used as separate modules.
How do they work ?
How to create static library in Linux ?
How to create dynamic library in Linux ?
How to use them in Linux:
To compile our main file, main.c, we need to tell the compiler to use libraries. So that the compiler knows where to look for libraries, it needs to be told the directory in which they are contained and the list of these libraries. The library directory is specified with the -L switch.
In our case the library is in the current directory, so the path to it will be in the form of a dot (-L.). The libraries used are listed with the -l switch, followed by the name of the library without the lib prefix and the ending .a. In our case, this key will look like -lfunctions. Now all with one command:
You can compile your code like this:
The expression, -l combined with holberton tells the compiler to look for a dynamic library called libholberton.so. The -L flag tells the compiler to look in the current directory for the library file. Typing and executing will generate an executable file called test.
What are the differences, advantages and drawbacks between static and dynamic libraries ?
In the table below, I have collected the features of each type of library.