I get the following linker error (Cross ARM C++ Linker) : undefined reference to `_sbrk'
when I try to compile some code like this:
however, if I just format the sprintf without addional parameters, like this:
sprintf(mystring,"This is mystring");
it works! Could you please give me any hint?
Thank you very much in advance.
P.D. I use KE06Z microcontroller.
that depends on
a) Kinetis SDK used or not
b) which library you are using
c) if you are using semihosting or not
sbrk() is a library routine used for dynamic memory allocation.
I hope this helps,
Thank you very much for your fast answer!
I started my project with one of your templates for my microcontroller, the one in this link:
So that I have tried to recompile the original projects (directly yours) by adding only the following:
to the main function and it crashes with the same error:
Invoking: Cross ARM C++ Linker
arm-none-eabi-g++ -mcpu=cortex-m0plus -mthumb -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -g3 -T "C:/IoT/KDS/WS_KE06Z/20160810_KE06Z/Project_Settings/Linker_Files/ProcessorExpert.ld" -Xlinker --gc-sections -L"C:/IoT/KDS/WS_KE06Z/20160810_KE06Z/Project_Settings/Linker_Files" -Wl,-Map,"20160810_KE06Z.map" --specs=nano.specs -o "20160810_KE06Z.elf" ./Static_Code/System/CPU_Init.o ./Static_Code/System/Peripherals_Init.o ./Static_Code/System/Vectors.o ./Sources/Events.o ./Sources/main.o ./Project_Settings/Startup_Code/startup.o ./Generated_Code/BitIoLdd1.o ./Generated_Code/BitIoLdd2.o ./Generated_Code/BitIoLdd3.o ./Generated_Code/BitIoLdd4.o ./Generated_Code/BitIoLdd5.o ./Generated_Code/Cpu.o ./Generated_Code/FRTOS1.o ./Generated_Code/KIN1.o ./Generated_Code/KSDK1.o ./Generated_Code/LEDB.o ./Generated_Code/LEDG.o ./Generated_Code/LEDR.o ./Generated_Code/LEDpin1.o ./Generated_Code/LEDpin2.o ./Generated_Code/LEDpin3.o ./Generated_Code/PE_LDD.o ./Generated_Code/PTD2.o ./Generated_Code/PTF1.o ./Generated_Code/Pins1.o ./Generated_Code/TU1.o ./Generated_Code/UTIL1.o ./Generated_Code/WAIT1.o ./Generated_Code/croutine.o ./Generated_Code/event_groups.o ./Generated_Code/heap_1.o ./Generated_Code/heap_2.o ./Generated_Code/heap_3.o ./Generated_Code/heap_4.o ./Generated_Code/heap_5.o ./Generated_Code/list.o ./Generated_Code/port.o ./Generated_Code/queue.o ./Generated_Code/tasks.o ./Generated_Code/timers.o
c:/freescale/kds_v3/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv6-m\libg_s.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
collect2.exe: error: ld returned 1 exit status
makefile:60: recipe for target '20160810_KE06Z.elf' failed
make: *** [20160810_KE06Z.elf] Error 1
The most strange thing to me is that if I don't format the content of sprintf, it links correctly and works! This means that testing the following code has no linker errors:
Any idea? I am absolutely lost and don't know how to go on.
Thank you very much for your collaboration.
I tried both your code pieces in that project, and they work without any issues on my side.
So I don't know what is the problem on your end.
Maybe add the missing function as
to your application to see what comes next.