Kyle A. answered 05/05/20
Senior Software Engineer Specializing in Systems Programming
Hi!
Both have advantages and disadvantages. A static library is linked into an executable at link time with all functions fully defined. This means that the executable does not depend on the presence of that library being installed on the system at runtime. However this comes at the cost of not easily being able to patch libraries independently of the main program. You are stuck with what was compiled in and this also creates a much larger executable in terms of binary size because so much more code is included.
A shared library (also known as a dynamic library, a DLL on Windows) on the other hand does not link in the definitions of the functions into the executable, they are instead loaded at runtime which means your executable will not work without a compatible version of the shared library being installed on the system you are running on. Now you have to manage multiple dependencies for your applications. This comes with the advantage of being able to change functions at runtime or upgrading individual libraries without upgrading the entire executable (for example to fix a simple security flaw in a function you use from the library). The shared library can also be used by multiple executables on the system at the same time saving some disk space vs every application statically linking all their libraries.
Hope that helps!