Link to rust static library from Rust

I have a static library which was compiled from a rust no_std project. It exposes a C interface and generally should be fine to be included in other projects. I can only use it as a static library because it has certain compiler flags.

I now want to link to it from another Rust application (which uses std). Unfortunately, I get many duplicate symbols errors, like:

note: rust-lld: error: duplicate symbol: __rust_alloc

Is there any way to include this? I cannot create a dynamic library, as my environment (Fortanix EDP) does not have dynamic linking support.

Can I maybe rename all the symbols in the static lib?

Thanks :slight_smile:

You can do a partial link (ld -r) keeping all public symbols only. But it doesn't sound like your first library is no_std if it has __rust_alloc.

And I'll repeat my previous advise:

If you want to change the compile flags for a single crate that's not the top crate, you should modify cargo or run rustc manually for all the crates in your dependency tree.

I tried a bit around and went with the manually compilation of the crates in the dependency tree. This seems to work fine.
Thanks a lot!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.