Quiz Entry - updated: 2026.07.14
What is the difference between static and dynamic linking?
Static linking copies all library code into the executable at build time; dynamic linking leaves it in shared .so files that are resolved at load time.
| Aspect | Static Linking | Dynamic Linking |
|---|---|---|
| When | At compile/link time | At load/run time |
| Result | All code in executable | Code in separate .so files |
| File size | Larger | Smaller |
| Memory | Each process has copy | Shared between processes |
| Updates | Must recompile | Just replace .so file |
| Startup | Faster | Slower (must resolve symbols) |
| Linker | ld (static linker) | ld-linux.so (dynamic linker) |
Static linking:
# Everything included in executable
$ gcc -static -o prog main.c
$ ldd prog
not a dynamic executable
Dynamic linking (default):
$ gcc -o prog main.c
$ ldd prog
linux-vdso.so.1
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
/lib64/ld-linux-x86-64.so.2
Tip: Most modern programs use dynamic linking for smaller binaries and shared library updates, but static linking is useful for maximum portability.
Go deeper:
Static library (Wikipedia) — copying library code in at build time, and its trade-offs.
Dynamic linker (Wikipedia) — the load-time alternative that keeps library code in shared
.sofiles.