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.
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
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.
The problem has little to do with _sbrk
itself, but rather your attempt to invoke the linker directly, bypassing the compiler driver. Instead, use the gcc command to invoke the linker and the -Wl,-linkeroptionhere
syntax to pass extra options to the linker.
One possible solution, if you must invoke the linker yourself.. Try repeating both libc.a
and libgcc.a
a second time at the end of the command line. There's also some "as group" linker option you could use to achieve this but I don't know it right off.
recently I also ran into this(again). the easiest solution which worked for me was to provide/redirect "malloc" and "free" apis to the one available from the SDK on which I was building my application.
Basically it happens because of mem management apis missing while linking. like the above answer mentions its not that _sbrk is specifically missing here. brk/sbrk syscall intenrally is used for heap management. hence the _sbrk ,missing link when it comes to mem management apis.
I noticed that adding -lnosys (ie libnosys.a) also helped a this to a degree in some integrations.
使用visualgdb(使用gcc)和nanolib,我不得不添加链接器标志
-specs=nosys.specs
I solved this problem and will post solution here so i give something back to comunity. The function _sbrk
is located inside NXP CDL package for ARM. Package is available for download (link is for all who dont know this already) here in subfolder CDL_v005/csps/lpc313x/bsps/ea3131/source
you will find source file named libnosys_gnu.c
which should be added to the project and compiled to object file and after that linked to executable file alongside other objects and libraries.
Best wishes and a lot of success.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.