Problem using sine and cosine functions

Hello,

I’m using the lastest version of Yagarto with LPC2138. I need to do some math based on sine and cosine, but the GCC always tells me “arm-elf-ld: cannot find -lm”. I have tried mainly everything but I cannot link with that library (libm.a). This is my make file, can anybody give me a hint? Thanks!

NAME   = TEST

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
SIZE	  = arm-elf-size

CFLAGS  = -I./ -I./include  -c -fno-common -O0 -g -mcpu=arm7tdmi
AFLAGS  = -ahls -mapcs-32 -mcpu=arm7tdmi -o crt.o
LFLAGS  = -Map ./release/${NAME}.map -T./config/lpc2138-FLASH.ld
CPFLAGS = -O ihex
ODFLAGS	= -x --syms

all: build size

clean:
	-rm ./release/crt.lst
	-rm ./release/main.lst 
	-rm./release/crt.o 
	-rm ./release/main.o 
	-rm ./release/main.out 
	-rm ./release/${NAME}.hex 
	-rm ./release/${NAME}.map 
	-rm ./release/${NAME}.dmp

size:
	@ echo "Size of Generated Hex File is "
	$(SIZE) --target=ihex -t ./release/${NAME}.hex

build: main.out
	@ echo "...copying"
	$(CP) $(CPFLAGS) ./release/main.out ./release/${NAME}.hex
	$(OD) $(ODFLAGS) ./release/main.out > ./release/${NAME}.dmp

main.out: crt.o delay.o io.o main.o system.o ./config/lpc2138-FLASH.ld 
	@ echo "..linking"
	$(LD) $(LFLAGS) -o ./release/main.out ./release/cpu/crt.o ./release/delay.o ./release/system.o ./release/main.o  ./release/cpu/io.o -L$(GCC_LIBS) -lm -lgcc 

crt.o: ./src/cpu/crt.s
	@ echo ".assembling crt.s"
	$(AS) $(AFLAGS) ./src/cpu/crt.s > ./release/cpu/crt.lst -o ./release/cpu/crt.o

main.o: ./src/main.c
	@ echo ".compiling"
	$(CC) $(CFLAGS) ./src/main.c -o ./release/main.o
	
delay.o: ./src/delay.c
	@ echo ".compiling delay"
	$(CC) $(CFLAGS) ./src/delay.c -o ./release/delay.o	
	
system.o: ./src/system.c
	@ echo ".compiling system"
	$(CC) $(CFLAGS) ./src/system.c -o ./release/system.o	

io.o: ./src/cpu/io.c
	@ echo ".compiling io"
	$(CC) $(CFLAGS) ./src/cpu/io.c -o ./release/cpu/io.o

Thanks!

Ezequiel

Hi,

You have -L$(GCC_LIBS) in the LD command, but GCC_LIBS is not defined.

The -lm will then interpreted as a library path.

I think the linker should be able to find system libraries that are in their default locations without a -L flag.

So try to just remove -L$(GCC_LIBS) or set a correct value for GCC_LIBS

Regards,

Magnus

mmm… that was a copy & paste error… my GCC_LIBS is

GCC_LIBS = “C:\Program Files\yagarto\lib\gcc\arm-elf\4.3.3”

But I found that this directory only has libgcc.a (-lgcc), so I have looked for libm.a and added that directory (C:\Program Files\yagarto\arm-elf\lib). Now it compiles, but it takes a lot much memory =)

Is there any way to avoid using the linker?

Thanks!

Ezequiel

Try adding --gc-sections to LFLAGS to remove unused code. This only works if each function is compiled to its own subsection though, but I believe that’s the default for arm-elf-gcc.

Building with -O0 generates a huge code footprint, because nothing is inlined and each statement gets its own sequence. This is so you can meaningfully use a debugger. -Os will generate about half the size of debug code.

Also, the file size includes debugging info and symbols. To actually check the sections sizes, use arm-elf-size.