undefined reference to `_sbrk' in Quectel MC60 MC60ECAR01A03 SDK [closed]

Multi tool use
undefined reference to `_sbrk' in Quectel MC60 MC60ECAR01A03 SDK [closed]
I am working on Quectel MC60 modem. For which I am using MC60ECAR01A03 SDK. I am trying to include my own external .c file into this SDK. After adding my .c files, my code is compiling. But when I call function from my library in any of example_.c file my code is not compiling. I am getting error:
C:Program Files
(x86)CodeSourcerySourcery_CodeBench_Lite_for_ARM_EABI/arm-none-eabi/lib/thumb/libc.a(lib_a-sbrkr.o):
In function _sbrk_r': sbrkr.c:(.text+0xc): undefined reference to
_sbrk'
_sbrk_r': sbrkr.c:(.text+0xc): undefined reference to
Please help me out to resolve this error.
Thank you in advance
This question appears to be off-topic. The users who voted to close gave this specific reason:
sbrk
What build system does the SDK use? Make? CMake? Have you included your object files to the link command?
– Ajay Brahmakshatriya
Jul 3 at 7:49
@Lundin ; "arm-none-eabi" indicates no OS.
– Clifford
Jul 3 at 9:33
@Clifford And sbrk indicates dynamic memory allocation, which only makes sense if there's an OS. Therefore we need to know what system that's actually used. If this is another "PC person finds a need for malloc on Cortex M0" problem, we can dismiss it as such.
– Lundin
Jul 3 at 9:42
We might differ on the "sense" of dynamic memory allocation without an OS. The OpenCPU SDK is a arguably rudimentary OS for the part (supports multi-tasking and IPC) and includes dynamic memory management according to this, but getting information on the part's memory resources is remarkably difficult - I found some reference and even a description of the core (ARM7EJ-S memory in the single figure Mb range I recall), but I cannot locate it again!
– Clifford
Jul 3 at 9:55
2 Answers
2
Since that is a linker error not a compiler error, your code is certainly compiling, but failing to link.
_sbrk_r
is the reentrant syscall referenced by the the Newlib C library required to support dynamic memory allocation on your target. It in turn references _sbrk
which does not exist.
_sbrk_r
_sbrk
You are required to provide appropriate syscalls to resolve library target dependencies. This may be provided in your SDK and you have failed to link it, or you may be expected to provide it yourself.
Alternatively of course, you might just avoid dynamic memory allocation in your code.
The SDK is a 40 Mb download that requires registration - otherwise I'd take a look for you.
– Clifford
Jul 3 at 9:10
Thank you Clifford
– Pavan NR
Jul 4 at 9:27
@PavanNR I appreciate you are new to SO, but you should read stackoverflow.com/help/privileges/comment on commenting. Up-voting and/or acceptance are the preferred methods of showing appreciation. To whoever the lurking down-voter is, a comment would be appreciated, so perhaps the answer might be improved.
– Clifford
Jul 4 at 19:49
I resolved this error successfully.I am posting my answer so that it will be small contribution to group. I had added missing _sbrk function in one .c file and added the same to my SDK.
Add below mentioned code in one .c file
#include <_syslist.h>
void *
_sbrk (incr)
int incr;
{
return 0;//(void *) prev_heap_end;
}
Thank you
That will resolve the link, but any attempt to allocate memory from the heap will fail at run-time.
– Clifford
Jul 4 at 19:41
Which ARM is it? Is there an OS?
sbrk
sounds like the raw Linux API, not even POSIX. So a random guess would be: using the wrong glibc library?– Lundin
Jul 3 at 6:38