Reputation: 2472
I'm starting to program in Rust and one of the first things I noticed is that Rust produces large binaries. For example, Rust's "Hello world!" binary is ~600K large, while the equivalent C binary is ~8K large.
After some searching I found this SO post which explains that Rust binaries are large because all the needed libraries are statically linked. But isn't that the case for C as well? When I write #include <stdio.h>
in C, aren't I statically linking the relevant I/O libraries as well? I have always assumed that answer is 'yes' but now I am doubting myself.
Upvotes: 1
Views: 560
Reputation: 3102
#include
copies the file contents to the source file, but if the header is nothing more than function declarations, all that would do is tell the program that those functions are available to be called in your code. The actual implementation may be defined in another file that would need to be linked in (either statically or dynamically) to your executable. If you look at the header for stdio.h
you would see that it only contains function prototypes.
Many compilers provide options to do either static or dynamic linking for the standard libraries.
Upvotes: 4