Any negative consequences to watch out for linking multiple independent Rust libraries into a C++ binary?

Viewed 86

If I have several different Rust crates that I'm linking (statically) into my executable (some vend C ABIs directly, some I write my own simple cxx bridge crate to wrap them, etc), do I still only end up with one instance of the Rust standard library in my executable? I think the answer is that each static library will have the standard library & the linker will end up collapsing them (provided I'm using the same Rust compiler for everything) but I just want to double-check.

Building on that, is there any risks of ODR violations/linker errors from dependency hell? I know Rust typically manages conflicting dependency versions elegantly when building within Cargo, but is that still solved when vending into an external binary? Specifically if I'm doing:

  • Crate A depends on v1 of crate C
  • Crate B depends on v2 of crate C
  • I build crates A & B independently to generate static libraries
  • I link liba.a and libb.a into my executable

Would that be an ODR violation, linkage error, or would everything work correctly? I could see it maybe being an ODR violation if Cargo needs to see the fact that you're trying to link two incompatible versions of a crate into the same binary.

0 Answers
Related