Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to _sbrk

Tags:

c

gcc

arm

sbrk

I am having a problem with _sbrk. In a link phase of compilation i use below comand to link my objects and i get undefined reference to _sbrk.

arm-none-eabi-ld -static -T linkerscript.ld -o exe timer_example.o /home/ziga/projects/cs_lite/arm-none-eabi/lib/libc.a /home/ziga/projects/cs_lite/lib/gcc/arm-none-eabi/4.5.1/libgcc.a

I am compiling for arm926ej-s and in ARM mode so i think i have chosen the right multilib (libc.a and libgcc.a) which is located in folder home/ziga/projects/cs_lite/arm-none-eabi/lib/.

I have been searching internet for _sbrk function and it is some sort of a memory managment call which isnt included in standard C libraries as it is dependant on microprocessor. So do I have to write _sbrk function on my own? How do I do it? Do you have any example for arm926ej-s? After writing this function I intend to compile it into an object file and link it together with other objects, libraries.

like image 772
71GA Avatar asked Apr 23 '11 13:04

71GA


2 Answers

This helps:

-mcpu=cortex-m4 -mthumb -specs=nano.specs -specs=nosys.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard

The important switches "seem" to be:

-specs=nano.specs -specs=nosys.specs

like image 169
nvd Avatar answered Sep 25 '22 10:09

nvd


I was having the same problem, and adding those to the linker flags helped:

-specs=nano.specs -specs=nosys.specs

Also, just with the nosys.specs fixed the issue, but the code size was a lot bigger.

like image 23
Kaká Barreto Avatar answered Sep 21 '22 10:09

Kaká Barreto