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.
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 traitCommon 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.
use embedded_alloc::Heap;
#[global_allocator]
static HEAP: Heap = Heap::empty();
// initialize HEAP in your startup code before first allocationOr avoid alloc entirely
Trace which dependency enabled alloc and disable that feature if heap use is not intended.
cargo tree -e features -i alloc
# then on the offending dep:
default-features = falseHow to prevent it
- Declare a
#[global_allocator]whenever ano_stdbuild needsalloc. - Audit feature flags so
allocis only pulled in intentionally. - Pin embedded dependency features to avoid surprise
allocactivation.