I’m learning about static and dynamic libraries. So far I understand why I would need a dynamic library. In case something is changing it’s good to plug in a newer version and all the applications will update automatically without even noticing.
a) Great for plugins,
b) multiple apps using the same library and
c) maintenance when you need to correct errors.
However, why would anyone use a static library? I mean what’s the advantage? Does sb have an example so I can understand it better? Is it to make a product proprietary?
EDIT: Due to the confusion in the comments. I understand what a static library is, and I also know the difference between a dynamic library. It was just beyond me why anyone would use a static library instead of just the source itself. I think I’m now starting to understand that a static library offers the following advantages:
a) better code maintenance
b) faster compiling times
A static library is basically a ZIP of object files. The only advantage it has over just distributing the object files is that it’s a single file that encompasses your whole library. Users can use your headers and the lib to build their applications.
Because it’s just a ZIP of object files, anything the compiler does to object files also works with static libraries, for example, dead code elimination and whole program optimization (also called Link-Time Code Generation). The compiler won’t include bits of the shared library in the final program that are unused, unlike dynamic libraries.
With some build systems, it makes link seams easier too. E.g. for MSVC++, I’ll often have a “production” EXE project, a “testing” EXE project, and put the common stuff in a static library. That way, I don’t have to rebuild all the common stuff when I do builds.