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?
_sbrkis defined inos/various/syscalls.c, so ensure this file is properly compiled and linked.Note that
_sbrkwill 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 anerrnoofENOMEM. Also see this answer for a more thorough explanation of theENOMEMissue.Also note that for embedded applications, especially when targetting high reliability, it might not be advisable to use dynamic memory allocation (of which
_sbrkis a part of) at all (see this detailed explanation)