|
|
|
|
|
by tom_mellior
2683 days ago
|
|
> When you statically link, only the functions that are actually called are included. 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. |
|
It's true that without proper care, you might end up importing a whole lot of useless stuff though.