What are the differences between static and dynamic libraries?
Why using libraries in general?
Libraries in programming languages are collections of prewritten code that users can use to optimize?tasks. For instance, people who want to write a higher-level program can use a library to make system calls instead of implementing those system calls over and over again. Library code is organized in such a way that it can be used by multiple programs that have no connection to each other, while code that is part of a program is organized to be used only within that one program.
How do they work?
In very simple terms a library is a file that consists of some useful code.
This code could be a simple function or a collection of functions, variables, classes, data structures. Generally a library is a code that will allow you to interact with a particular aspect of the OS. e.g. libraries like stdio.h
A library could also be a collecction of mathematical or logical operations. e.g. math.h
The general philosophy behind writing a library is to
How to create and use a Library in Linux
Building static libraries is fairly simple.
In conclusion:
Static libraries are better for quickly getting a library up and running, but it also has drawbacks. It gets compiled into every program that uses it. This means you have to manually update every program that uses it when you edit your library.
Dynamic libraries are nice because they load only 1 copy of themselves in memory when you run a program, so you don’t eat up as much memory when you start running multiple programs using that library. The other benefit is that your programs don’t need to be recompiled when you recompile your shared library.
I hope the article was useful.