_sbrk exists, linker can't find it

OP #2581284
Rate this post
• ▲ useful
▼ not useful
Hello,

I'm trying to compile a program for a stm32f4-discovery board using code 
sourcery g++ lite and I'm having a peculiar problem. My program uses the 
"new operator" and I had to implement the _sbrk function.

Here is the linker command:
arm-none-eabi-g++ -mthumb -mcpu=cortex-m4 -march=armv7e-m 
-mfix-cortex-m3-ldrd -o main.elf -O2  -g -Wall -Werror 
-Wl,-T/home/li/dev/arm_rc/ld/cs3.ld  main.o start_cs3.o newlib_stubs.o

_sbrk is in newlib_stubs.c (.o). Knowing that order of the files on the 
command line counts, I tried moving newlib_stubs.o as first/last 
argument but with no success.

What could be wrong?

Note that the C version of the program that uses malloc is compiling 
just fine (arm-none-eabi-gcc instead of arm-none-eabi-g++)

Thanks,
Liviu
Moderator #2581302
Rate this post
• ▲ useful
▼ not useful
Liviu Vasut wrote:

> Note that the C version of the program that uses malloc is compiling
> just fine (arm-none-eabi-gcc instead of arm-none-eabi-g++)

Did you perhaps compile newlibs_stubs with the C++ compiler, so the
names got their C++ mangling?

Try running arm-none-eabi-nm on the file newlib_stubs.o, and see
which symbol it is reporting for _sbrk.

Btw., the order of explicitly mentioned .o files on the commandline
(almost) doesn't matter.  It's only the order of library files that
matters.

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.