Blogpost about the build process
โ Rust ๐ 2025-07-08 ๐ค surdeus ๐๏ธ 20Found a blogpost about ELF Linking and Symbol Resolution :: Noratrieb's blog
Simplified summary with questions
cargo build uses rustc which compiles each crate separately. Dependencies are also a compilation units (CUs).
Each CU โincluding our own crateโ is compiled to an object file (with.o suffix). The .os have undefined symbols since the deps are not included yet.
Linking is the process of resolving those undefined symbols in the crate's object file.
Static Libraries (.a) are bundles of object files. They are included in the final binary.
- Why is this extra level needed and not just separate object files?
- Also the non-bundled
.ofiles are included right?
For Dynamic Libraries (*.so) the content is instead searched at Runtime, it's not in the binary. This is done by ld-linux before our program's main runs.
In summary, linking static libraries (and object files) resolves the symbol and puts content in; linking dynamic libraries skip the last step (don't put content in).
That's just the intro of the blogpost, the deeper part read in the link.
5 posts - 3 participants
๐ท๏ธ rust_feed