EMbitz

Full Version: undefined reference to `_sbrk '
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good day. I'm a beginner, I'm sorry if I ask or describe something incorrectly.
Started a project on STM32F407ZGT6. Blinking is normal, but as soon as I connect the previously written code with standard libraries, I get - c: / program files (x86) /embitz/1.11/share/em_armgcc/bin /../ lib / gcc / arm-none-eabi / 5.4. 1 /../../../../ arm-none-eabi / lib / armv7e-m / fpu \ libg_n.a (lib_a-sbrkr.o): In function `_sbrk_r ':
sbrkr.c Sad. text._sbrk_r + 0xc): undefined reference to `_sbrk '.
As far as I understand, the libg_n.a library is not connected / I heard that this is done with some kind of keys. How do I do it at Embitz? Maybe something else is wrong?
[attachment=65]
(07-08-2021, 02:07 PM)mh444 Wrote: [ -> ]Good day. I'm a beginner, I'm sorry if I ask or describe something incorrectly.
Started a project on STM32F407ZGT6. Blinking is normal, but as soon as I connect the previously written code with standard libraries, I get - c: / program files (x86) /embitz/1.11/share/em_armgcc/bin /../ lib / gcc / arm-none-eabi / 5.4. 1 /../../../../ arm-none-eabi / lib / armv7e-m / fpu \ libg_n.a (lib_a-sbrkr.o): In function `_sbrk_r ':
sbrkr.c Sad. text._sbrk_r + 0xc): undefined reference to `_sbrk '.
As far as I understand, the libg_n.a library is not connected / I heard that this is done with some kind of keys. How do I do it at Embitz? Maybe something else is wrong?

Code:
/// From linker script
extern size_t* _sheap;  // Start of the heap
extern size_t* _eheap;  // End of the heap

/////////////////////////////////////////////////
/// \brief Important to guard our heap if it's in limits
///
/// \param incr int
/// \return caddr_t
///
///
caddr_t _sbrk(int incr)
{
    static caddr_t heap_end;

    if (heap_end == 0)
        heap_end = (caddr_t)&_sheap;

    // Do we have space?
    if( (heap_end + incr) > (caddr_t)&_eheap)
    {
        errno = ENOMEM;
        return (caddr_t) -1;
    }

    // Allocate the memory
    caddr_t prev_heap_end = heap_end;
    heap_end += incr;

    return (caddr_t) prev_heap_end;
}
Thanks. But I don't quite understand how to link this code with libg_n. And one more thing - the error described above occurs only in Release. In Debug - everything is ok.