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

Hi,

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

Introduction

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/global_alloc.rs at master · rust-embedded/embedded-alloc · GitHub, but the following error ocurrs:

Error itself

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

Question

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 !