Compiling C++ statically
To properly compile a static C++ binary on Linux you have to supply
-static ,
-static-libgcc
and -static-libstdc++ when linking.
That's fucked up.
Never EVER think that linking (at link time or runtime) is easy or obvious.
I link my current pet project with:
g++ -Wl,-z,now -Wl,-z,relro -pie -static-libstdc++
The binary then seems to work across the systems I currently want to run it on.
Specifically it makes me able to run the binary compiled on Debian Testing on a
Debian Stable installation.
Skipping that whole dynamic libraries thing is something Go got right.
Update: some clarification on why you'd want to compile statically
Let's start with the reason for wanting to compile static in the first place.
While shared libraries are better in some aspects, "save RAM" is no longer a good reason
for always compiling dynamically. There are reasons why you'd want dynamic linking still,
...