Background: When cortex_m3 uses FreeRTOS to enable the running time statistics function.
Compilation error during compilation:
/Data/user_ Home//build_ Tools/GCC arm none eabi-/bin// Lib/gcc/arm-none-eabi/6.2.1/../../../../..// Arm-none-eabi/lib/thumb/v7-m/libc A (lib_a-sbrkr.o): in function`_ Sbrk_ R’:
Sbrkr c: (.Text.\u sbrk_r+0xc): undefined reference to`_ Sbrk’
Collect2: error: LD returned 1 exit status
Makefile:155: recipe for target’all’failed
Make: * * * [all] error 1
Cause: by default, arm GCC uses startfiles, which results in link compilation failure when calling some functions (malloc, free, sprintf…) that are not implemented at the bottom.
Promotion: if the compiler reports Error: undefined reference to `_sbrk’ `_read’ `_write’ `_lseek’ `_isatty’ `_fstat’ , it is the same reason.
Solution:
Method 1: if the project does not need these functions, find the direct mask function.
Method 2: once and for all. The link fails because these functions are not implemented, so you can rewrite these underlying functions or add library files with these functions, such as libnosys a. Add compilation parameter —specs=nosys.specs can be used.
After adding, if the compiler reports the following errors:
/Data/user_ Home/ /build_ Tools/GCC arm none eabi-/bin// Lib/gcc/arm-none-eabi/6.2.1/../../../../..// Arm-none-eabi/lib/thumb/v7-m/libnosys A (sbrk.o): in function`_ Sbrk’:
Sbrk c: (.Text.\u sbrk+0x18): undefined reference to `end’
Collect2: error: LD returned 1 exit status
Makefile:155: recipe for target’all’failed
Make: * * * [all] error 1
This is because the ‘end’ symbol is not defined in the .lds linker script, so find the project’s xx.lds file to set that script for the heap location, e.g.
.heap : { . = ALIGN(4); __HEAP_START = .; . += 0x2000; __HEAP_MAX = .; end = __HEAP_MAX; PROVIDE(end = .); } > ram