2 ms·
When I first came to C++ from Rust I was surprised by the regularity of linker errors. Rust must be compiled with a linker as well but I don't think I've ever s
by ChadNauseam 2y ago
When I first came to C++ from Rust I was surprised by the regularity of linker errors. Rust must be compiled with a linker as well but I don't think I've ever seen a linker error, except when doing exotic things far outside of my typical day-to-day.
I guess rustc detects the situations in which the linker would throw an error and then throws its own error preemptively. It leads to a much better user experience than the C++ one, since the error messages produced by the linker are always unnecessarily terrible
- Joker_vD 2y ago> I guess rustc detects the situations in which the linker would throw an error and then throws its own error preemptively. Pretty much. The crucial difference between C and Rust which enables Rust to do this sort of detection is that in Rust, the extern things are anchored in modules (crates? whatever), and so when you import things, you have to say where you are importing them from. extern void *magic_init(int); extern void *magic_stuff(void*, const char*, int); extern void magic_fini(void*); versus use crate_of_magic::{init, stuff, fini}; It even enables one to actually type-check against the imported crate during the compilation (IIRC if Cargo can't locate the imported crate to look into it, it will refuse to build the project), as opposed to hoping that the headers you've included are correctly describing the object file you'll be linking against.
- 0x457 2y agoOnly time I get linker errors in rust is when it's linking some dynamic library written in C.