Hacker News new | past | comments | ask | show | jobs | submit login

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.




> It is a bit painful but it works.

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.

[1] https://savannah.gnu.org/patch/?9687


> 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).




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: