The differences between Static and Dynamic Libraries

Hadir Jenni
2 min readDec 14, 2020

Why using libraries and what are they?

As functions, libraries are blocks of code that may be reused to save time and space in a program. The most significant advantage to use libraries is that instead of writing all your code by yourself, you can also get external ones. There is two types of libraries : the static and dynamic ones.

How do they work ?

How to create static library in Linux ?

How to create dynamic library in Linux ?

How to use them in Linux:

Static library:

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:

What are the differences, advantages and drawbacks between static and dynamic libraries ?

In the table below, you’ll get the difference between static and dynamic libraries

--

--