The main issue with -static is that glibc is a massive PITA that hates being statically linked due to its reliance on dlopen() for locale and NSS management. It's therefore not recommended linking it anything but dynamically and afaik there is no "pick all static but libc" option in Clang or GCC. The other option is using an Alpine chroot and statically link using musl, but there are lots of compatibility issues with certain programs that massively abuse of GNUisms (i.e see anything ever written by Pöttering) and not every library has a .a available in the package manager, so you must compile them also.
Yep. The glibc tries very hard to avoid static linking (since the infamous times of Ulrich Drepper). It is almost as if they hated static linking for some personal reasons, and then they artificially add the NSS and locale excuses that make it impossible.
Yet you can still compile a static executable that calls the dlopen function. And you can also select (by using some -B and -W magic options) exactly which libraries you want to link statically and dynamically on your executable. It is a bit painful but it works. The only thing that does not work is when you rely on GPU code, where your program needs to be linked directly to specific graphics drivers. I hope in a few years the kernel itself will allow a gpu abstraction for that to work.
Great point about musl. To distribute (your) program as a linux static binary, write it in standard C and compile it using musl.
That's an understatement... especially if you're using autotools with libtool. Which, coincidentally, seems to be unmaintained. I tried submitting a patch on their GNU Savannah[1], and it's soon celebrating its second birthday... last official release in 2015...
And yet this is the "GNU standard" which a huge part of the packages found on an average Linux install - especially the smaller and more foundational pieces - are built with. It's mindbogglingly sad.
> especially if you're using autotools with libtool.
Then you had it coming!
I do not understand why, in this day and age, the autotools shitfuckery is still necessary. You can write a portable makefile that will compile your program on all widespread unixes (linux distros, all the BSDs and macOS). Using CI tools you can verify in a few minutes whether it compiles correctly everywhere. The autotools and cmake systems are most often useless cruft (except if you want to compile on windows, in that case cmake is probably inevitable).