3 ms·
> 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
by 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.