Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I avoid import collisions when importing my own standard library?

Tags:

rust

I am trying to import my own std library, but when I am compiling with crates dependencies I have this issue:

error: duplicate lang item in crate `std`: `f32`.
  |
  = note: first defined in crate `my_std`.

error: duplicate lang item in crate `std`: `f64`.
  |
  = note: first defined in crate `my_std`.

error: duplicate lang item in crate `std`: `panic_fmt`.
  |
  = note: first defined in crate `my_std`.

I tried to overwrite the library by writing extern crate my_std as std

What would be the easy way to fix that - and not modify this for all dependencies?

like image 938
David Avatar asked Jan 02 '26 00:01

David


1 Answers

You can compile your code without the Rust standard library by using #![no_std] attribute in your crate root. Note that there are some caveats to doing this with an executable (as opposed to a library), and you will need to manually include libc for a binary.

like image 161
Jason Watkins Avatar answered Jan 04 '26 12:01

Jason Watkins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!