error[E0463]: can't find crate for `alloc`


I'm developing a project that runs on an embedded device, more precisely, an Arduino Mega.


I'm trying to use an allocator in order to be able to use Vectors. I've tried to use GitHub - rust-embedded/embedded-alloc: A heap allocator for embedded systems and replicate the following example: embedded-alloc/examples/ at master · rust-embedded/embedded-alloc · GitHub, but the following error ocurrs:

Error itself

error[E0463]: can't find crate for `alloc`
 --> src\
4 | extern crate alloc;
  | ^^^^^^^^^^^^^^^^^^^ can't find crate


Why doesn't it find the crate, how can it be added?

Extra data

  • Compiler used: rustc 1.73.0-nightly

Are you using build-std to build the standard library for your target? If so you need to tell cargo to build liballoc and not just libcore. For example using -Zbuild-std=core,alloc or build-std = ["core", "alloc"] in the config where you enable build-std.

1 Like

I added "alloc" to the build-std = ["core"] and it worked. I had a wrong idea of how those modules are splitted at low level.

Thanks !

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.