EmbDev.net

Forum: ARM programming with GCC/GNU tools "undefined reference to memcpy" error - please help!


Author: magnetron (Guest)
Posted on:
Attached files:

Rate this post
0 useful
not useful
hello dear forum ,

I am trying to compile a C program for STM32F407 microcontroller
with OlimexODS  ( Eclipse + yagarto compiler )

I get the error;

"undefined reference to memcpy" error
as you can see in the attached picture

---------------------- makefile ------------
CROSS_COMPILE = arm-none-eabi-

CC = $(CROSS_COMPILE)gcc
SIZE = $(CROSS_COMPILE)size
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
LD = $(CROSS_COMPILE)ld
AS = $(CROSS_COMPILE)as

# Flags
CFLAGS = -Wall -fno-common -c -g -mcpu=cortex-m3 -mthumb
CFLAGS += -g $(OPTIMIZATION) $(INCLUDES) -DTRACE_LEVEL=$(TRACE_LEVEL)
ASFLAGS = -g -mapcs-32
LDFLAGS = -g -v -nostartfiles
OBJCOPYFLAGS = -O binary
OBJDUMPFLAGS = -x --syms -S

why the linker cannot find a libray function
which is 40 years old already ?

Author: teo (Guest)
Posted on:

Rate this post
0 useful
not useful
please post the c-code

Author: guest (Guest)
Posted on:

Rate this post
0 useful
not useful
>please post the c-code
Why? This is a linker error.

Author: Fred S. (Guest)
Posted on:

Rate this post
0 useful
not useful
Did you include string.h or memory.h?
I am not familiar with your IDE, but memcpy() usually requires one of 
these include files.

Author: magnetron (Guest)
Posted on:
Attached files:

Rate this post
0 useful
not useful
hello

as you can see in the attachment
if I include any of standart library header files

it gives "unresolved inclusion" error

besides the original "undefined reference" error is still there
if I build again

Author: Walleby (Guest)
Posted on:
Attached files:

Rate this post
0 useful
not useful
Hey,

im using the same IDE with YAGARTO-Toolchain. I had the same problems 
few days ago.
Do you have this 4 path in your project? Otherwise the compiler wont 
find your included files.

Author: Walleby (Guest)
Posted on:

Rate this post
0 useful
not useful
Ahh... Sry for double pictures...

Author: Oliver (Guest)
Posted on:

Rate this post
0 useful
not useful
>if I include any of standart library header files

Well, simply not putting it in is probably not the right solution.

All these effects point into the direction of a incomplete or defect 
installation of the tool chain. Apparently the compiler is missing the 
system include dir paths, and the linker is missing the system lib path.

Oliver

Author: Johann (Guest)
Posted on:

Rate this post
0 useful
not useful
Is there a specific reason why you call target-ld by hand and don't use 
the driver target-gcc for linking?

If you call it by hand you will have to set all the options by hand that 
the driver would set for you...

Author: magnetron (Guest)
Posted on:

Rate this post
0 useful
not useful
>All these effects point into the direction of a incomplete or defect
>installation of the tool chain. Apparently the compiler is missing the
>system include dir paths, and the linker is missing the system lib path.

I totally agree

however this IDE I downloaded from Olimex
the name of this package is OlimexODS

the package sucessfully installed
only I had to install Java seperately

and I had to adjust the PATH variable of my windows XP
to point to ...yagarto\bin

Author: Franky (Guest)
Posted on:

Rate this post
0 useful
not useful
Would all of you PLEASE stop talking all your include file nonsense?

This is a linker error, include files have NOTHING to do with it. The 
linker doesn't find thee libraries. Libraries, not headers!

Author: Johann L. (gjlayde)
Posted on:

Rate this post
0 useful
not useful
As I already said, the problem is that you call the linker with the 
wrong options.  Use the driver for linking, not a naked ld, i.e. instead 
of.

LD = $(CROSS_COMPILE)ld
AS = $(CROSS_COMPILE)as

you want

LD = $(CROSS_COMPILE)gcc
AS = $(CROSS_COMPILE)gcc

For example, -nostartfiles makes no sense as an ld flag because ld knows 
nothing at all about start files.  -nostartfiles is a flag for the 
driver, i.e. for $(CROSS_COMPILE)gcc.

Author: magnetron (Guest)
Posted on:

Rate this post
0 useful
not useful
>Author: Johann L.

hello I took your advice

however this time it gives error about map file
c:/olimexods/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/bin/ld.exe:./main.map: file format not recognized; treating as linker script
c:/olimexods/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/bin/ld.exe:./main.map:2: syntax error
collect2: ld returned 1 exit status
make: *** [main.out] Error 1 

if I comment this out in linker command line
>-Map main.map
it compiles

I have some questions ;
1) is this map file important ?
2) if I link with gcc instead of ld , will the code be stable ?
will it link with latest version of library ?

thanks

Author: Johann L. (gjlayde)
Posted on:

Rate this post
0 useful
not useful
magnetron wrote:
>>Author: Johann L.
>
> however this time it gives error about map file
>
>
c:/olimexods/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/bin/ld.exe:./main.map:
> file format not recognized; treating as linker script
> c:/olimexods/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/bin/ld.exe:./main.map:2:
> syntax error
> collect2: ld returned 1 exit status
> make: *** [main.out] Error 1 
>
> if I comment this out in linker command line
>>-Map main.map
> it compiles
>
> I have some questions ;
> 1) is this map file important ?

It's important to find out what goes wrong. It's a dump file and
won't change the compilation result, just like temporary files like
-save-temps.

> 2) if I link with gcc instead of ld , will the code be stable ?

Is it stable not?  Add -v to the gcc command line and observe the
linker command it issues.  Prosumably, the command line generated by
gcc is much closer to a correct one tha a comman line you write by hand.

Calling the ld by hand instead of by means of the driver (gcc) is the
most common reason for problems with the linker.

> will it link with latest version of library ?

I don't know your library. And Idon't know STM or ARM.

It's just the general scheme how gcc works. If GCC and Binutils and the 
libraries are configured and built correctly, it will work.

Author: Oliver (Guest)
Posted on:

Rate this post
0 useful
not useful
> if I link with gcc instead of ld , will the code be stable ?

Your trials with using ld directly did not produce any usable code at 
all.

The program "gcc" itself is neither a compiler nor a linker. It is the 
standard interface to all elements of the tool chain (compiler, linker, 
assembler, ...), and calls all of them, using the right paprameters.

Therefore using gcc is the most appropriate option.

Oliver

Author: magnetron (Guest)
Posted on:

Rate this post
0 useful
not useful
c:/olimexods/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/lib\libg.a(lib_a-sbrkr.o): In function `_sbrk_r':
C:\msys\1.0\home\yagarto\newlib-build\arm-none-eabi\newlib\libc\reent/../../../../../newlib-1.18.0/newlib/libc/reent/sbrkr.c:60: undefined reference to `_sbrk'
collect2: ld returned 1 exit status
make: *** [main.out] Error 1

hello forum,

I squeezed the error down to above message after I changed the
...ld to ...gcc

I searched the forum for past messages
some people faced the same error like me
but I didnot understand anything

what is this _sbrk?
how can I get rid of it ?

thanks

Author: Johann L. (gjlayde)
Posted on:

Rate this post
0 useful
not useful
_sbrk is used to get memory from the OS, e.g. during malloc.

Thus, _sbrk is typically supplied by your OS or libgloss or similar.

Author: magnetron (Guest)
Posted on:

Rate this post
0 useful
not useful
hello thanks for the answer but

I have no operating system
this is a standalone application

on an ARM Cortex M4 microcontroller

thank you, how can I proceed ?

Author: Johann L. (gjlayde)
Posted on:

Rate this post
0 useful
not useful
Use an OS, implement _sbrk, don't use malloc et al. or implement your 
own malloc et al.

Most likely you don't really want malloc.

Author: Oliver (Guest)
Posted on:

Rate this post
0 useful
not useful
or read the documentation of newlib. google will give you also some more 
info on that issue.

Oliver

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.