How to solve linker error: sbrk.c(1,1): error: undefined reference to `end'

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
I get this linker error message when compiling my project for atsam4n8b:

Invoking: ARM/GNU Linker : 6.3.1
        c:/program files (x86)/atmel/studio/7.0/toolchain/arm/arm-gnu-toolchain/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m\libnosys.a(sbrk.o): In function `_sbrk':

sbrk.c(1,1): error: undefined reference to `end'

 

I have tried to search the site and the web but have been unable so far to find a solution. Can anyone please assist? I have attached the linker files.

 

At first I also ran into problem with __bss_start__ and __bss_end__ but found the solution was to add these to the linker file. But I am puzzled why this was needed in the first place, as I was expexting this to work out of the box. I mean, I have defined any custom segments so shouldn't the default linker file just work?

 

Kind regards,

Christian

Attachment(s): 

This topic has a solution.

Last Edited: Wed. Mar 18, 2020 - 04:51 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Found the answer myself by reading the linker documentation.

 

1. There is no need to add  __bss_start__ and __bss_end__ definitions. Use option '--gc-sections' to garbage collect unused section

2. In the linker file add 'end = _sheap;' to the heap section

 

I am pretty sure that I had tried (2) before writing my initial post (which is why I wrote it because I couldn't get it to work), but when I tried now it worked. Maybe I made a typo the first time