简体   繁体   中英

Could not compile `lazy_static`

I'm having a hard time cross-compiling an embedded Rust project that worked before for a raspberry pi. I have all the needed deps in Cargo.toml but on doing:

$ cargo build --target thumbv7m-none-eabi

I get the following error.

error[E0463]: can't find crate for `std`
 --> /home/.cargo/registry/src/github.com-1ecc6299db9ec823/lazy_static-1.4.0/src/inline_lazy.rs:9:1
  |
9 | extern crate std;
  | ^^^^^^^^^^^^^^^^^ can't find crate
  |
  = note: the `thumbv7m-none-eabi` target may not support the standard library
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `lazy_static` due to previous error

$ rustup show

installed targets for active toolchain
--------------------------------------

thumbv7m-none-eabi
x86_64-unknown-linux-gnu

active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (default)
rustc 1.64.0-nightly (38b72154d 2022-07-11)

Compilation used to work previously without lazy_static as a dependency in cargo.toml,now I don't understand why this is happening.

By default lazy_static depends on the rust standard library, which as the compiler told you

may not be supported on the thumbv7m-none-eabi target

If you do not need the standard library in your project you can enable the no-std feature of lazy_static like this:

lazy_static = { version = "1.5.0", features = ["spin_no_std"] }

as described here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM