EmbDev.net

Forum: ARM programming with GCC/GNU tools How to use newlib in ARM Projects?


Author: T_RAIN (Guest)
Posted on:

Rate this post
0 useful
not useful
Hello everybody!

I'm very new to the ARM controllers. I'm currently working with an
ATSAM7 and the YAGARTO Toolchain.

The toolchain works fine but i'm missing functions like sprintf and
malloc!

I read that they are avialable at the newlib library. How do i include
this library into my code? I couldn't find any newlib directory in the
installation path of Yagarto.

Do i need special linker or complier flags when my code uses sprintf or
malloc functions?

Currently i got the folliwing error:

Code:
undefined reference to `malloc'


Tanks a lot

Greetings
T_RAIN

Author: Martin Thomas (Guest)
Posted on:

Rate this post
0 useful
not useful
T_RAIN wrote:
> Currently i got the folliwing error:
>
> Code:
> undefined reference to `malloc'

Is this the complete message? Did you include <stdio.h>? Any message
about with "sbrk"? Did you search the forum for newlib, syscalls and
stdo? Please paste or attach the complete output from the build-process.

Author: T_RAIN (Guest)
Posted on:

Rate this post
0 useful
not useful
Thanks for your reply:

Here is the complete output of the build process:

make -k all
...compiling main.c
arm-elf-gcc -I./ -c -fno-common -O0 -g main.c
...linking
arm-elf-ld -v -lc  -Map main.map -Tdemo_at91sam7_blink_flash.cmd -o
main.out crt.o  main.o lcd.o lowlevelInit.o debug.o libgcc.a
GNU ld version 2.17
main.o: In function `main':
I:\SOFTWARE\5.Semester\ARM_Projects\demo_at91sam7_blink_flash/main.c:49:
undefined reference to `printf'
make: *** [main.out] Error 1
make: Target `all' not remade because of errors.


This is the Makefile that i'm currently using:

# ***************************************************************
#      Makefile for Atmel AT91SAM7S256 - flash execution       
#                                                              
#                                                              
# * James P Lynch  September 3, 2006                            *
# ***************************************************************

NAME   = demo_at91sam7_blink_flash

# variables
CC      = arm-elf-gcc
LD      = arm-elf-ld -v -lc
AR      = arm-elf-ar
AS      = arm-elf-as
CP      = arm-elf-objcopy
OD    = arm-elf-objdump

CFLAGS  = -I./ -c -fno-common -O0 -g
AFLAGS  = -ahls -mapcs-32 -o crt.o
LFLAGS  =  -Map main.map -Tdemo_at91sam7_blink_flash.cmd
CPFLAGS = --output-target=binary
ODFLAGS  = -x --syms

OBJECTS = crt.o  main.o lcd.o lowlevelInit.o debug.o


# make target called by Eclipse (Project -> Clean ...)
clean:
  -rm $(OBJECTS) crt.lst main.lst main.out main.bin main.hex main.map
main.dmp


#make target called by Eclipse  (Project -> Build Project)
all:  main.out
  @ echo "...copying"
  $(CP) $(CPFLAGS) main.out main.bin
  $(OD) $(ODFLAGS) main.out > main.dmp

main.out: $(OBJECTS) demo_at91sam7_blink_flash.cmd
  @ echo "...linking"
  $(LD) $(LFLAGS) -o main.out $(OBJECTS) libgcc.a

crt.o: crt.s
  @ echo "...assembling crt.s"
  $(AS) $(AFLAGS) crt.s > crt.lst

main.o: main.c  include\AT91SAM7X256.h include\board_ex256.h
include\registers.h include\lcd.h
  @ echo "...compiling main.c"
  $(CC) $(CFLAGS) main.c

lcd.o: lcd.c  include\AT91SAM7X256.h include\ext_registers.h
include\lcd.h include\bits.h
  @ echo "...compiling lcd.c"
  $(CC) $(CFLAGS) lcd.c

lowlevelInit.o: lowlevelInit.c include\AT91SAM7X256.h
include\board_ex256.h
  @ echo "...compiling lowlevelInit.c"
  $(CC) $(CFLAGS) lowlevelInit.c

debug.o: debug.c include\AT91SAM7X256.h include\board_ex256.h
include\lib_AT91SAM7XC256.h
  @ echo "...compiling debug.c"
  $(CC) $(CFLAGS) debug.c


and yes i inculded:
#include <stdio.h>
#include <stdlib.h>

to my main.c file

I got these error message when i'm using functions like printf, malloc,
sprintf...


Is the liggcc file the newlib library. If not please tell me where I can
find it  in the yagarto filestructure.


Thank's a lot

Greetings,
T_RAIN


Martin Thomas wrote:
> T_RAIN wrote:
>> Currently i got the folliwing error:
>>
>> Code:
>> undefined reference to `malloc'
>
> Is this the complete message? Did you include <stdio.h>? Any message
> about with "sbrk"? Did you search the forum for newlib, syscalls and
> stdo? Please paste or attach the complete output from the build-process.

Author: Tony (Guest)
Posted on:

Rate this post
0 useful
not useful
T_RAIN wrote:
> Hello everybody!
>
> I'm very new to the ARM controllers. I'm currently working with an
> ATSAM7 and the YAGARTO Toolchain.
>
> The toolchain works fine but i'm missing functions like sprintf and
> malloc!
>
> I read that they are avialable at the newlib library. How do i include
> this library into my code? I couldn't find any newlib directory in the
> installation path of Yagarto.
>
> Do i need special linker or complier flags when my code uses sprintf or
> malloc functions?
>
> Currently i got the folliwing error:
>
> Code:
> undefined reference to `malloc'
>
>
> Tanks a lot
>
> Greetings
> T_RAIN

Hi Both,

I have same kind of problem (almost started a new topic). I'm receiving
this error:

c:/winarm/bin/../lib/gcc/arm-elf/4.1.1/../../../../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+0x64): undefined reference to `_sbrk_r'
mallocr.c:(.text+0x84): undefined reference to `_sbrk_r'
c:/winarm/bin/../lib/gcc/arm-elf/4.1.1/../../../../arm-elf/lib\libc.a(ma 
llocr.o):
In function `_malloc_r':
mallocr.c:(.text+0x424): undefined reference to `_sbrk_r'
mallocr.c:(.text+0x4cc): undefined reference to `_sbrk_r'
collect2: ld returned 1 exit status

I would like to use stdlib.h or otherwise I have to code many standard
functions by my self.

Br. Tony

Author: Michael Fischer (mifi)
Posted on:

Rate this post
0 useful
not useful
Hello Tony,

take a look here:

http://www.sparkfun.com/cgi-bin/phpbb/viewtopic.ph...

At the end you will find the solution.

Best regards,

Michael

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.