EmbDev.net

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


von magnetron (Guest)


Attached files:

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 ?

von teo (Guest)


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

von guest (Guest)


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

von Fred S. (Guest)


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

von magnetron (Guest)


Attached files:

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

von Walleby (Guest)


Attached files:

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

von Walleby (Guest)


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

von Oliver (Guest)


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

von Johann (Guest)


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...

von magnetron (Guest)


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

von Franky (Guest)


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

von Johann L. (gjlayde)


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.

von magnetron (Guest)


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

von Johann L. (gjlayde)


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.

von Oliver (Guest)


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

von magnetron (Guest)


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

von Johann L. (gjlayde)


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

von magnetron (Guest)


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

von Johann L. (gjlayde)


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

von Oliver (Guest)


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

Oliver

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.