Add examples for different utilities

This commit is contained in:
2026-02-24 13:46:16 +01:00
parent bacba9e8c8
commit 04c7146e84
5 changed files with 213 additions and 8 deletions

View File

@@ -239,21 +239,26 @@ g++ main.cpp wrapper.cpp -lsqlite3 -o app
```bash
# Inspect symbols
nm -C -g lib.a # demangled, global symbols only
nm -u main.o # undefined (unresolved) symbols
objdump -d my.o # disassembly
readelf -s my.o # ELF symbol table
nm -C -g libmath.a # demangled, global symbols only
nm -u main.o # undefined (unresolved) symbols
objdump -d math_lib.o # disassembly
readelf -s math_lib.o # ELF symbol table
# Trace linker decisions
g++ main.o -lmylib -Wl,--verbose 2>&1 | grep "attempt"
ld --trace my.o # shows each file the linker considers
g++ main.o -L. -lmath -Wl,--verbose 2>&1 | grep "attempt"
ld --trace math_lib.o # shows each file the linker considers
# Check shared lib deps
ldd ./app
chrpath -l ./app # show embedded RPATH
chrpath -l ./app # show embedded RPATH
# fallback if chrpath is not installed:
readelf -d ./app | grep -E 'RPATH|RUNPATH'
# Demangle a mangled symbol
c++filt _ZN4Math4sqrtEd # → Math::sqrt(double)
c++filt _ZN4Math4sqrtEd # → Math::sqrt(double)
# Pipe nm output through c++filt to demangle all symbols at once
nm -g libmath.a | grep " T " | awk '{print $NF}' | c++filt
```
**Useful flags:**