Building Dynamic Libraries
Resourceful Code Reuse — by Dmitry Zinoviev (16 / 20)
👈 Building Static Libraries | TOC | Chapter 3 Reuse Code at Runtime (C and Python) 👉
As the name suggests, a dynamic library (also known as a shared library) is in the first place a library: a collection of object files that have something in common. But unlike a static library, it is dynamic. What’s the difference?
Understanding Dynamic Linking
The first difference between a static library and a dynamic library is in the name. The extension of a dynamic library on Linux/macOS is so (“shared object,” such as libmyjson.so). Microsoft calls them “dynamic linked libraries” with the extension dll, as in libmyjson.dll.
The second difference is in the way a library is linked to the rest of the program. A static library is permanently linked to an executable file, and each process has its copy of the library. On the bright side, a statically linked program’s functionality isn’t affected by library upgrades, specifically by disappearing libraries. (Think about what may happen if you incidentally remove the standard C library libc!) On the dark side, statically linked programs pollute memory (hello, Occam!) and aren’t affected by library upgrades. It might sound like a contradiction to say that not being affected by library upgrades is both the bright and dark side, but it is true. Sometimes, you want to replace libraries with better, faster, and more secure…