Hacker News new | past | comments | ask | show | jobs | submit login

> I'm not sure I understand the use case here. Are you asking if you can depend on two versions of the same crate, for a crate that exports a `#[no_mangle]` or `#[export_name]` function?

Yes, exactly.

> Other than that, you cannot.

so, to the question "Can a Rust binary use incompatible versions of the same library?", then the answer is definitely "no". It's not yes if it cannot cover one of the most basic use cases when making OS-native software.

To be clear: no language targeting OS-native dynamic libraries can solve this, the problem is in how PE and ELF works.




I agree the answer is no in the abstract, but it is not very useful in practice.

Nobody writing Rust needs to cover this "basic use case" you're referring to, so it is the same as people saying "unsafe exists so Rust is no safer than C++". In theory that's true, in practice in 18 months, 604 commits and 60,008 LoC I wrote `unsafe` exactly twice. Once for memory mapping something, once for skipping UTF-8 validation that I'd just done before (I guess I should have benchmarked that one as it is probably premature).

In practice when developing Rust software at a certain scale you will mix and match incompatible library versions in your project, and it will not be an issue. Our project has 44 dependencies with conflicting versions, one of which appears in 4 incompatible versions, and it compiles and runs perfectly fine. In other languages I used (C++, python), this exact same thing has been a problem, and it is not in Rust. This is what the article is referring to


Rust uses -sys crates to link to non-native dependencies, with a links key in the manifest - https://doc.rust-lang.org/cargo/reference/build-scripts.html...

This mechanism allows Cargo to prevent multiply linking to an external library.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: