EmbDev.net

Forum: ARM programming with GCC/GNU tools C++ and WinARM


von Karsten (Guest)


Rate this post
useful
not useful
Hello all,

i've a little problem to build an C++ project with WinARM.

I can compile all sources.
But when I would link the objects files arm-elf-c++ stops with some
error messages like this:

C:/DOKUME~1/kbrandt/LOKALE~1/Temp/cc2jbaaa.o: In function
`_start':../system_source/crt0.S:(.text+0xe0): multiple definition of
`_start'
c:/winarm/bin/../lib/gcc/arm-elf/4.0.2/../../../../arm-elf/lib/crt0.o:c: 
/winarms/newlib-1.14.0/libgloss/arm/crt0.S:67:
first defined here
c:/winarm/bin/../lib/gcc/arm-elf/4.0.2/../../../../arm-elf/lib\libc.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\libc.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\libc.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\libc.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\libc.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\libc.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\libc.a(st 
dio.o):
In function `__sclose':stdio.c:(.text+0xf8): undefined reference to
`_close_r'

After I've added the -v option to the compiler call, I found this in the
compiler output:

Configured with: ../../gcc-4.0.2/configure --enable-languages=c,c++
--enable-interwork --enable-multilib --with-gcc --with-gnu-ld
--with-gnu-as --with-stabs --disable-shared --disable-threads
--disable-win32-registry --disable-nls --target=arm-elf --with-newlib
--prefix=c:/WinARM -v

My first question is:

What will be call here? I can't find configure executable in the WinARM
folder.

The next question is:

This call of configure has the option --with-newlib. In my mind, this is
the reason for the undefined references. How can I avoid this?

Last but not least:

For my project I've to develop and link my own startup code. You can
this above
as following output:

C:/DOKUME~1/kbrandt/LOKALE~1/Temp/cc2jbaaa.o: In function
`_start':../system_source/crt0.S:(.text+0xe0): multiple definition of
`_start'

But when I look in the comiler output, I can the mysterious things.
The Linker bind also startup code from WinARM/lib folder to the project.
This results accidentally in multiple definition of '_start'.
But isn't the worst. Only I've now two startup code in my project.
What is my mistake here? I dont know?

Any suggestions are welcome.

Karsten

von Martin Thomas (Guest)


Rate this post
useful
not useful
Karsten wrote:

> I can compile all sources.
> But when I would link the objects files arm-elf-c++ stops with some
> error messages like this:
>
> C:/DOKUME~1/kbrandt/LOKALE~1/Temp/cc2jbaaa.o: In function
> `_start':../system_source/crt0.S:(.text+0xe0): multiple definition of
> `_start'
> c:/winarm/bin/../lib/gcc/arm-elf/4.0.2/../../../../arm-elf/lib/crt0.o:c: 
/winarms/newlib-1.14.0/libgloss/arm/crt0.S:67:
> first defined here

It seems that you are using a "generic" crt0. Usualy you have to provide
your own startup-code. I don't know for which target the generic version
is made. Since there are so many different ARM-controllers with a
different settings try to create your own startup-code based on
examples.

>c:/winarm/bin/../lib/gcc/arm-elf/4.0.2/../../../../arm-elf/lib\libc.a(m 
allocr.o):
> In function `_malloc_r':mallocr.c:(.text+0x430): undefined reference to
> `_sbrk_r'
> :mallocr.c:(.text+0x5ec): undefined reference to `_sbrk_r'

The newlib needs support functions which connect the generic code to the
target-specific-code. sbrk_r is one of them (memory handling). See the
newlib-manual and the example-codes. sbrk is not very target-specific.
The newlib-lpc is a good source of information.

isatty, read, lseek, close etc. are also system-calls.

> What will be call here? I can't find configure executable in the WinARM
> folder.

See the newlib-manual, the newlib-lpc source (util-dir) and the
syscalls.c-files in the examples.

> This call of configure has the option --with-newlib. In my mind, this is
> the reason for the undefined references. How can I avoid this?

See the gcc-manual. It's explained there.

> For my project I've to develop and link my own startup code. You can
> this above
> as following output:
>
> C:/DOKUME~1/kbrandt/LOKALE~1/Temp/cc2jbaaa.o: In function
> `_start':../system_source/crt0.S:(.text+0xe0): multiple definition of
> `_start'

Mybe because of the "default" crt0. Compile with "-nostartfiles" and
provide your own startup.S/crt0.S

> But when I look in the comiler output, I can the mysterious things.
> The Linker bind also startup code from WinARM/lib folder to the project.
> This results accidentally in multiple definition of '_start'.
> But isn't the worst. Only I've now two startup code in my project.
> What is my mistake here? I dont know?

- use your own startup, compile with nostart
- implement the syscalls

See the makefiles included in the examples.

Hope this helps,
Martin Thomas

von Karsten Brandt (Guest)


Rate this post
useful
not useful
Hello Martin,

thanks for your reply.

The problem seems to be solved.
I've added the linker option -nostartfiles and now only my own startup
code will be linked to the project.
Also I've added the modified syscall.c from the

WinARM\examples\at91sam7s64_basicusb\AT91SAM7S-BasicUSB\src folder

and it seems work without problems now.

Only one question is open for me:

I've looked in the code for the sbrk function.
Here was reserved memory for a new() call by example.
But were will be freed this memory?
And who will reset the heap pointer?

Many thanks,
Karsten

von Martin Thomas (Guest)


Rate this post
useful
not useful
Karsten Brandt wrote:

> I've looked in the code for the sbrk function.
> Here was reserved memory for a new() call by example.
> But were will be freed this memory?
> And who will reset the heap pointer?

You may take a look into the newlib source-code for the malloc and free
and the functions called by this "high-level-routines". sbrk is just an
interface function so maybe the newlib-functions have the functionality
you are missing. So far I do not know much about the
implemention-details since I do not use malloc/free et al in embedded
systems. There is a newlib mailing-list which should be a better place
to ask this questions.

Martin Thomas

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.