# undefined reference to `_sbrk' / `_write' / `_close' / `_exit' (newlib stubs)

**Code:** `undefined reference to _sbrk` · **Category:** C/C++ · **Seen on:** C/C++, ARM, Embedded

newlib needs a few system-call stubs on bare metal, and none were provided.

## Meaning

Functions such as `malloc`, `printf` and `exit` call `_sbrk`, `_write`, `_close`, `_exit`. On a microcontroller you must implement them, or link `--specs=nosys.specs`.

## Common causes

- No syscalls file in the project
- Missing `--specs=nosys.specs`
- Using malloc/printf without retargeting
- nano.specs without stubs

## Quick fix

1. Add `--specs=nosys.specs` to the link flags
2. Implement `_write` and `_sbrk` for your UART and heap
3. Avoid malloc on small targets

## Detailed fix by platform

### GCC

1. `arm-none-eabi-gcc ... --specs=nano.specs --specs=nosys.specs`

## How to diagnose

1. **Specs** — nosys/nano linked?
2. **Stubs** — Implemented?
3. **Use** — malloc/printf?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/arm-none-eabi-undefined-sbrk)
