undefined reference to _sbrk C/C++ Origin: Application & API OSI layer 7 · Application Last updated 2 Dec 2026

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

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

Exact message you may see undefined reference to `_sbrk'undefined reference to `_write'undefined reference to `_exit'newlib syscalls
Seen on: C/C++ ARM Embedded

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?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

alloc-dealloc-mismatch — AddressSanitizer: alloc-dealloc-mismatch (malloc vs operator delete) (C/C++)alloc-dealloc-mismatchattempting double-free — AddressSanitizer: attempting double-free on address (C/C++)attempting double-freecall of overloaded is ambiguous — C++: error: call of overloaded 'f(int)' is ambiguous (C/C++)call of overloaded is…cannot declare variable to be of abstract type — C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions) (C/C++)cannot declare variab…no debugging symbols — gdb: (No debugging symbols found in ./app) (C/C++)no debugging symbolsreference to is ambiguous — C++: error: reference to 'X' is ambiguous (using namespace std conflicts) (C/C++)reference to is ambig…region FLASH overflowed — arm-none-eabi-ld: region `FLASH' overflowed by N bytes (C/C++)region FLASH overflow…undefined reference to — C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status (C/C++)undefined reference toundefined…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.