I'm using ChibiOS 3.x to write an embedded application. When compiling/linking it, I encounter an error message like this:
/usr/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/armv7e-m/libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
Where is _sbrk
defined and how can I resolve this issue?
_sbrk
is defined inos/various/syscalls.c
, so ensure this file is properly compiled and linked.Note that
_sbrk
will work correctly if and only ifCH_CFG_USE_MEMCORE == TRUE
(you can change that inchconf.h
). Else,malloc()
will always return 0 and result in anerrno
ofENOMEM
. Also see this answer for a more thorough explanation of theENOMEM
issue.Also note that for embedded applications, especially when targetting high reliability, it might not be advisable to use dynamic memory allocation (of which
_sbrk
is a part of) at all (see this detailed explanation)