1

I am developing on SAM3X8E, I am using the GCC C++ compiler and atmel studio 7. I am trying to include the stdio library and I keep getting the error:

"undefined reference to end" in sbrk

following this post:

https://community.atmel.com/forum/how-solve-linker-error-sbrkc11-error-undefined-reference-end

I explicitly added end to the heap section of the linker script in the heap section via,

end = sheap;

I'm not sure what's going on, sbrk should see the linker variable.

artless noise
  • 21,212
  • 6
  • 68
  • 105
FourierFlux
  • 439
  • 5
  • 13

1 Answers1

0

I solved this problem. Add _sbrk function.

extern int  _sheap;

caddr_t _sbrk( int incr )

{

    static unsigned char *heap = NULL;
    unsigned char *prev_heap;
    
    if (heap == NULL) {
        heap = (unsigned char *) &(_sheap);
    }
    prev_heap = heap;
    heap += incr;
    
    return (caddr_t) prev_heap;
}
Johan
  • 3,667
  • 6
  • 20
  • 25
chai
  • 1