EmbDev.net

Forum: ARM programming with GCC/GNU tools YAGARTO: undefined reference to `strcpy'


Author: Dmitry Timas (cryon)
Posted on:

Rate this post
0 useful
not useful
Hi!

I’m using YAGARTO + Eclipse, and have no problem compiling code without
standard libs, but have them with… For example following code gives an
error:

#include <string.h>

int main(void)
{
  char a[10];
  char b[10];
  strcpy(a,b);
}


> Linking...
arm-elf-ld -v -Map main.map -Tlpc2378.ld -o main.out main.o
GNU ld (GNU Binutils) 2.18
main.o: In function `main':
test06/main.c:9: undefined reference to `strcpy'
make: *** [main.out] Error 1


My makefile looks like:


NAME   = lpc2378

CC      = arm-elf-gcc
LD      = arm-elf-ld -v
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 -mapcs-stack-check
LFLAGS  = -Map main.map -Tlpc2378.ld
CPFLAGS = -O binary
HEXFLAGS = -O ihex
ODFLAGS  = -x --syms

all: test

test: main.out
  @ echo "> Copying.."
  $(CP) $(CPFLAGS) main.out main.bin
  $(OD) $(ODFLAGS) main.out > main.dmp
  @echo "> Building hex"
  $(CP) $(HEXFLAGS) main.out main.hex
  @ echo "> Sorting output..."
  @ mv *.o *.lst *.dmp *.hex *.map *.out *.bin out

main.out: main.o lpc2378.ld
  @ echo "> Linking..."
  $(LD) $(LFLAGS) -o main.out main.o


clean:
  @ echo "Cleaning..."
  @ rm ./out/*.*

Any suggestions please

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
Dmitry Timas wrote:
>> Linking...
> arm-elf-ld -v -Map main.map -Tlpc2378.ld -o main.out main.o
> GNU ld (GNU Binutils) 2.18
> main.o: In function `main':
> test06/main.c:9: undefined reference to `strcpy'
> make: *** [main.out] Error 1

Here your linker command line shows that you have not linked any
libraries.

If you call the linker directly, you have to specify the standard
libraries and their paths. To add to the complexity, there are multiple
versions of the standard library depending on the target for Thumb, ARM,
Interwork, FPA support etc.

I believe that the simplest solution is to invoke the linker indirectly
through the compiler front end (arm-elf-gcc or arm-elf-g++). This
implicitly determines the correct libraries from the compiler options.
Otherwise you need some appropriate -L<path> arguments, and at least -lc
and -lgcc (in that order), and possibly -lm ahead of those if using the
math library.

Clifford

Author: Clifford Slocombe (clifford)
Posted on:

Rate this post
0 useful
not useful
If you do wish to call arm-elf-ld directly, something like the
following:

LFLAGS  = -Map main.map -Tlpc2378.ld
-L$(YAGARTO_TOOLS_ROOT)/lib/gcc/arm-elf/4.0.2/interwork
-L$(YAGARTO_TOOLS_ROOT)/arm-elf/lib/interwork -nostdlibs --start-group
-lc -lm -lgcc --end-group

works for me. Note you may want to select something other than teh
interwork libraries, but these give the widest compatibility at the
expense of very slightly larger code size.

Also not that the use of YAGARTO_TOOLS_ROOT. Either set this as an
environment variable or a macro within the makefile, or replace directly
wit the path for your installation.

The -start-group/-end-group may not be strictly necessary. It avoids any
issues with link order and dependencies at the possible cost of
increased build time but in post circumstances this is insignificant.

Clifford

Author: Dmitry Timas (cryon)
Posted on:

Rate this post
0 useful
not useful
Clifford Slocombe wrote:
> I believe that the simplest solution is to invoke the linker indirectly
> through the compiler front end (arm-elf-gcc or arm-elf-g++). This
> implicitly determines the correct libraries from the compiler options.
> Otherwise you need some appropriate -L<path> arguments, and at least -lc
> and -lgcc (in that order), and possibly -lm ahead of those if using the
> math library.
>

Very good explanation, thank you very much!

As you suggested I used front end (arm-elf-gcc) & Martin’s makefile,
works fine for me till now!

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.