Dynamic Library vs Static Library — Key Differences
-
Linking time
- Static: resolved and copied into the executable at compile/link time.
- Dynamic: resolved at load/runtime by the OS loader (shared at runtime).
-
Binary size
- Static: larger executables (library code embedded).
- Dynamic: smaller executables (library code kept in separate files like .so/.dll).
-
Memory usage
- Static: each process holds its own copy of library code.
- Dynamic: one shared copy in memory can be used by multiple processes (more efficient).
-
Performance
- Static: slightly faster call overhead (no runtime symbol resolution).
- Dynamic: small runtime overhead for loading/indirection; may increase paging/TLB misses in some cases.
-
Deployment & updates
- Static: simpler deployment (self-contained), but updating requires recompiling/re-distributing the executable.
- Dynamic: easier updates and smaller patches (replace the shared library), but introduces runtime dependency management and potential compatibility issues.
-
Compatibility & stability
- Static: immune to “DLL hell” / version mismatches (stable behavior until rebuilt).
- Dynamic: susceptible to ABI/version incompatibilities if libraries change.
-
Use cases
- Static: embedded systems, single-file distribution, performance-critical or locked-down builds.
- Dynamic: large applications, plugin/modular architectures, systems where memory/disk sharing and frequent updates matter.
-
File extensions & platforms
- Static: .a (Unix), .lib (Windows).
- Dynamic: .so (Linux/Unix), .dylib (macOS), .dll (Windows).
-
Symbol visibility & control
- Static: symbols resolved at link
Leave a Reply