Static Linking Nightmares: An SDK Provider's Lament

2025-07-22
Static Linking Nightmares: An SDK Provider's Lament

As an SDK provider, we're expected to offer both dynamic and static linking options. Static archives (.a) seem simple, but are fraught with peril. The linker's default behavior atomizes the archive, picking and choosing object files, potentially leading to bloated binaries and runtime crashes due to constructor/destructor ordering issues. While -Wl,--whole-archive helps, it forces inclusion of all library files, regardless of need. Namespace clashes within static archives also pose significant problems. To overcome these challenges, the author proposes a new "Static Bundle Object" (.sbo) file format. This would offer the symbol visibility guarantees of a shared object, avoiding many linking issues, even if it means sacrificing some potential binary size optimization. The author argues that a stable linking ecosystem is worth the trade-off.

Development