Shared libraries: DLL and .so
In short: Shared libraries (DLL on Windows, .so on Linux, .dylib on macOS) are loaded into the program at startup or runtime and shared by many programs.
In more detail: The counterpart is static linking, where the library code is copied into the executable.
In Depth
- Advantages of shared libraries: Less memory (the code sits in RAM once), fixes without recompiling programs, smaller files.
- Disadvantages: “DLL hell” with version conflicts, the program does not start if the library is missing (
libfoo.so: cannot open shared object file). - Search: The dynamic loader searches fixed paths. On Linux:
LD_LIBRARY_PATH,/etc/ld.so.conf, embeddedRPATH. On Windows first the program folder. - Tools:
ldd program(Linux) shows dependencies,otool -Lon macOS, Dependencies/dumpbinon Windows. - Static versus dynamic: Statically linked programs (Go, Rust default) are easy to ship, dynamic ones easier to update.
- Security: A planted library in the search path is a known attack route (DLL hijacking).
See also: dependencies and libraries