Static & Shared Libraries
Prerequisites: The C standard: C89 through C23
Instead of recompiling shared code into every program that uses it,
it's packaged into a library. A static library (.a) is copied
directly into the final executable at link time; a shared
library (.so on Linux, .dylib on macOS, .dll on Windows) stays
a separate file, loaded at runtime and potentially shared in memory
across multiple running programs.
# static
gcc -c mathutils.c -o mathutils.o
ar rcs libmathutils.a mathutils.o
gcc main.c -L. -lmathutils -o program
# shared
gcc -shared -fPIC mathutils.c -o libmathutils.so
gcc main.c -L. -lmathutils -o program
A shared library can be updated (a security patch, for instance) without recompiling every program that links against it — as long as its public interface doesn't change.