Help with a C++ compilation error

Hi,

I’m adapting code I’ve run elsewhere and been converting to your data structures when that makes sense. I do use new a couple times (in constructors). Having successfully sorted out my minor code errors, my last compilation error seems to be this, and I have no idea what to make of it.

/opt/OwlProgram.online/Tools/gcc-arm-none-eabi-5_4-2016q3/bin/…/lib/gcc/arm-none-eabi/5.4.1/…/…/…/…/arm-none-eabi/lib/armv7e-m/fpu/libc.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 make[1]: *** [/tmp/owl/owl-build-PUPZpC/patch.elf] Error 1 make: *** [patch] Error 2 ERROR: Patch build failed.

Any thoughts?

PDue

Okay, so _sbrk is pulled in when system malloc is used. It is fine to use new (anywhere in code called by the Patch constructor), but for malloc and free we have macros defined to avoid the libc implementations.

Probably what you need to do is add an include:
#include "basicmaths.h" to .c and .cpp files (the latter can instead #include "Patch.h")

If it is not malloc, then there could be some other libc call that uses it e.g. printf() (don’t use printf!)

Found it! Thanks for your response. I had also found a post previously that suggested possibly something to do with memory, but in the end that wasn’t it. It was the libc printf bit. No, I didn’t have printf, but I did have an assert that I hadn’t noticed, and even if I had, wouldn’t have been sure if it would ignore it or not. Maybe just maybe this will work in time to use it in a late night gig tonight!

1 Like