Linker problems while moving C to C++

Guest #1171083
Rate this post
• ▲ useful
▼ not useful
Hi,

I am using WinARM-20060117-1 with gcc 4.0.2.

I successfuly compiled my first program written in pure C.
After then I started to port my funtions into object oriented style
using C++. However after several compile and fix loops it seems that
I stuck into a linker problem on low level functions:

c:/winarm/bin/../lib/gcc/arm-elf/4.0.2/../../../../arm-elf/lib\libg.a(ma 
llocr.o):
In function `_malloc_r':mallocr.c:(.text+0x430): undefined reference to
`_sbrk_r'
:mallocr.c:(.text+0x5ec): undefined reference to `_sbrk_r'
c:/winarm/bin/../lib/gcc/arm-elf/4.0.2/../../../../arm-elf/lib\libg.a(fr 
eer.o):
In function `_malloc_trim_r':mallocr.c:(.text+0x48): undefined reference
to `_sbrk_r'
:mallocr.c:(.text+0x70): undefined reference to `_sbrk_r'
:mallocr.c:(.text+0xb4): undefined reference to `_sbrk_r'
c:/winarm/bin/../lib/gcc/arm-elf/4.0.2/../../../../arm-elf/lib\libg.a(ma 
kebuf.o):
In function `__smakebuf':makebuf.c:(.text+0x44): undefined reference to
`_fstat_r'
:makebuf.c:(.text+0xe4): undefined reference to `isatty'
c:/winarm/bin/../lib/gcc/arm-elf/4.0.2/../../../../arm-elf/lib\libg.a(st 
dio.o):
In function `__sread':stdio.c:(.text+0x1c): undefined reference to
`_read_r'
c:/winarm/bin/../lib/gcc/arm-elf/4.0.2/../../../../arm-elf/lib\libg.a(st 
dio.o):
In function `__swrite':stdio.c:(.text+0x78): undefined reference to
`_lseek_r'
:stdio.c:(.text+0x9c): undefined reference to `_write_r'
c:/winarm/bin/../lib/gcc/arm-elf/4.0.2/../../../../arm-elf/lib\libg.a(st 
dio.o):
In function `__sseek':stdio.c:(.text+0xc0): undefined reference to
`_lseek_r'
c:/winarm/bin/../lib/gcc/arm-elf/4.0.2/../../../../arm-elf/lib\libg.a(st 
dio.o):
In function `__sclose':stdio.c:(.text+0xf8): undefined reference to
`_close_r'
make.exe: *** [main.elf] Error 1


Is this specific to C++?
Isn't WinARM intended to be used with C++?
How can I solve this problem?

Thanks alot
Regards
Cem Eryasar
#1171084
Rate this post
• ▲ useful
▼ not useful
All of the 'undefined references' are functions from the Newlib C
library 'system calls' layer. They are specific to the target platform
and must be provided by you, (support for some targets is provided with
WinARM). This is not specific C++, you need these functions for C code
also, so if it worked for your C code, then you must have omitted the
required object code from the C++ link.

Compare your C link log with your C++ log. Post the logs if you can't
see the problem.

I can assure you that WinARM supports C++ - I have built a 600Kb C++
application using it. Being an in-house board and an unsupported chip, I
had to provide the syscalls myself - I hope you are luckier!

Clifford
Guest #1171085
Rate this post
• ▲ useful
▼ not useful
Thanks for the reply!

I am using a Philips LPC-2138 based board. Is this CPU amongst the
supported ones? I can see that there are several example projects for
Philips LPC chips within the WinARM directory. Where should I look at to
find that out?

Cem


Clifford Slocombe wrote:
> All of the 'undefined references' are functions from the Newlib C
> library 'system calls' layer. They are specific to the target platform
> and must be provided by you, (support for some targets is provided with
> WinARM).
Guest #1171086
Rate this post
• ▲ useful
▼ not useful
Cem Eryasar wrote:
> I am using a Philips LPC-2138 based board. Is this CPU amongst the
> supported ones? I can see that there are several example projects for
> Philips LPC chips within the WinARM directory. Where should I look at to
> find that out?

There is an example for an LPC2138 in the "example-collection" from
where you can copy the linker-skript and startup-code. You can use a
copy of the syscalls.c from another LPC-example or link with the
newlib-lpc (libnewlib-lpc.a) for the newlib-syscalls. There are examples
for both methods.
Guest #1171087
Rate this post
• ▲ useful
▼ not useful
Thanks a lot Martin for the pointers.

Btw, is there any document telling the inner dynamics of this linking
issue and syscalls stuff? Before I go back into hacking loop I'd like to
read some basics if possible...

Cem


Martin Thomas wrote:
> Cem Eryasar wrote:
>> I am using a Philips LPC-2138 based board. Is this CPU amongst the
>> supported ones? I can see that there are several example projects for
>> Philips LPC chips within the WinARM directory. Where should I look at to
>> find that out?
>
> There is an example for an LPC2138 in the "example-collection" from
> where you can copy the linker-skript and startup-code. You can use a
> copy of the syscalls.c from another LPC-example or link with the
> newlib-lpc (libnewlib-lpc.a) for the newlib-syscalls. There are examples
> for both methods.

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.