Skip to content
Latchkey

Rust "no global memory allocator found" (no_std) in CI

A no_std build links the alloc crate (something needs heap allocation) but no allocator is registered. Without std, there is no default allocator, so you must declare a #[global_allocator].

What this error means

A #![no_std] crate fails to link with error: no global memory allocator found but one is required; link to std or add #[global_allocator]. Common when a dependency pulls in alloc on an embedded/bare-metal target.

cargo
error: no global memory allocator found but one is required; link to std
or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait

Common causes

alloc used without an allocator

A no_std build (directly or via a dependency) uses alloc types like Vec/Box, but no #[global_allocator] is registered to back them.

A dependency enabled alloc unexpectedly

Feature unification turned on an alloc-using feature of a shared crate, dragging in heap usage your bare target cannot satisfy without an allocator.

How to fix it

Register a global allocator

Declare a #[global_allocator] static implementing GlobalAlloc.

Rust
use embedded_alloc::Heap;

#[global_allocator]
static HEAP: Heap = Heap::empty();
// initialize HEAP in your startup code before first allocation

Or avoid alloc entirely

Trace which dependency enabled alloc and disable that feature if heap use is not intended.

Terminal
cargo tree -e features -i alloc
# then on the offending dep:
default-features = false

How to prevent it

  • Declare a #[global_allocator] whenever a no_std build needs alloc.
  • Audit feature flags so alloc is only pulled in intentionally.
  • Pin embedded dependency features to avoid surprise alloc activation.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →