Dynamic Linking
Purpose
Guide agents through Linux dynamic linking: shared library creation, RPATH/RUNPATH configuration, soname versioning, dlopen/dlsym plugin patterns, LD_PRELOAD interposition, and symbol visibility control.
Triggers
- "Cannot open shared object file: No such file or directory"
- "How do I set RPATH so my binary finds its shared library?"
- "How do I use dlopen/dlsym for a plugin system?"
- "What's the difference between RPATH and RUNPATH?"
- "How do I use LD_PRELOAD to intercept a function?"
- "How do I version my shared library with soname?"
Workflow
1. Creating a shared library
2. Soname versioning convention
Inspect soname:
3. RPATH vs RUNPATH
$ORIGIN resolves to the directory of the binary at runtime — use it for relocatable installations.
4. Library search order
Debug with:
5. dlopen / dlsym plugin pattern
Link with -ldl:
6. LD_PRELOAD interposition
LD_PRELOAD loads a library before all others — its symbols override the application's.
7. Symbol visibility control
Limit exported symbols to reduce binary size and avoid clashes:
Or use a linker version script:
Build with -fvisibility=hidden by default and explicitly mark public API:
8. Common errors
For RPATH, soname, and ld.so configuration details, see references/ld-rpath-soname.md [blocked].
Related skills
- Use
skills/binaries/elf-inspectionto inspect shared library sections and symbols - Use
skills/binaries/linkers-ltofor linker flags and symbol resolution - Use
skills/binaries/binutilsfornm,objdump,stripon shared libs - Use
skills/compilers/gccfor-fPIC,-sharedand related compiler flags


