"undefined reference to memcpy" error - please help!

Guest #2942319
Rate this post
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 ?
Attached files:
Guest #2942383
Rate this post
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
Guest #2942706
Rate this post
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...
Guest #2943098
Rate this post
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
#2943347
Rate this post
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.
Guest #2944434
Rate this post
useful
not useful
>Author: Johann L.

hello I took your advice

however this time it gives error about map file
1
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
2
c:/olimexods/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/bin/ld.exe:./main.map:2: syntax error
3
collect2: ld returned 1 exit status
4
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
#2944948
Rate this post
useful
not useful
magnetron wrote:
>>Author: Johann L.
>
> however this time it gives error about map file
>
>
1
c:/olimexods/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/bin/ld.exe:./main.map:
2
> file format not recognized; treating as linker script
3
> c:/olimexods/yagarto/bin/../lib/gcc/arm-none-eabi/4.5.1/../../../../arm-none-eabi/bin/ld.exe:./main.map:2:
4
> syntax error
5
> collect2: ld returned 1 exit status
6
> 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.
Guest #2945075
Rate this post
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
Guest #2945776
Rate this post
useful
not useful
1
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':
2
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'
3
collect2: ld returned 1 exit status
4
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

Reply

Please log in before posting.

or

Log in with Google account

Registration is free and takes only a minute.

Register now