This is not true in general.
For this code:
#include <stdio.h>
int main(void)
{
puts("hello world\n");
return 0;
}
both GCC 7.3.0 and Clang 6.0.0[1] on my system generate an 828 KB binary when compiling with -static. The binary includes a whole bunch of stuff, including all the printf variants, many of the standard string functions, wide string functions, lots of vectorized memcpy variants, and a bunch of dlsym-related functions.By using -ffunction-sections -fdata-sections -Wl,--gc-sections (per https://news.ycombinator.com/item?id=19170667) I get this down to 804 KB. Still not quite what you suggest.
[1] Clang might just be using the same linker as GCC here, and you might blame including the extra stuff on the linker.
$ gcc -O3 foo.c -flto -static -o foo
$ du -sh foo
828K foo
$ strip foo
$ du -sh foo
760K foo
Could you post a complete command line and the version of the compiler you have showing how to make this work with static linking?uClibc and musl libc have much better support for static linking, and you will be able to make a much smaller binary with them than you would static linking against glibc.
$ musl-gcc test.c -O2
$ ls -laB a.out
.rwxr-xr-x 15,776 roblabla 15 Feb 16:49 a.out
$ musl-gcc test.c -O2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static
$ ls -laB a.out
.rwxr-xr-x 17,864 roblabla 15 Feb 16:48 a.out
Static linking with MUSL added 2088 bytes of overhead. Likely only the code that was needed.It's true that without proper care, you might end up importing a whole lot of useless stuff though.
FWIW, I believe (but could very well be wrong) the reason that this works this well with MUSL is that every function is defined in its own translation unit. I doubt that Qt and KDE do that.