EmbDev.net

Forum: ARM programming with GCC/GNU tools Linker problems while moving C to C++


Author: Cem Eryasar (Guest)
Posted on:

Rate this post
0 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

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 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

Author: Cem Eryasar (Guest)
Posted on:

Rate this post
0 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).

Author: Martin Thomas (Guest)
Posted on:

Rate this post
0 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.

Author: Cem Eryasar (Guest)
Posted on:

Rate this post
0 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.

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
Cem Eryasar wrote:
>
> 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...
>

Yes. The Newlib manual, in the doc folder, or online
http://sources.redhat.com/newlib/libc.html#SEC195

Clifford

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.