Posts tagged: _sbrk chibios

ChibiOS “undefined reference to `_sbrk'” linker error

If we get this linker error with ChibiOS:

/usr/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/lib/thumb/v6-m/libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
collect2: error: ld returned 1 exit status

we simply need to add syscalls.c to be compiled, add the following to CSRC in the Makefile:

$(CHIBIOS)/os/various/syscalls.c

We should underline that _sbrk will work correctly if and only if CH_CFG_USE_MEMCORE == TRUE (editable in chconf.h). Else, malloc() will always return 0 and result in an errno of ENOMEM.

WordPress Themes