Ok, so I reinstalled my development enviroment on the mac using the latest build of avr-gcc (4.4.2), avr-libc and avrdude from the Fink project.
Problem is when compiling I keep on getting a linker issue "multiple definition of …".
I have narrowed it down to a floating point issue associated with "libm.a" (using strtod()). All indications says to just include this library, but i'm unsure of how to do this in my Make file (below).
DEVICE = atmega128
CLOCK = 8000000
PROGRAMMER = -c stk600 -P usb
OBJECTS = main.o a2d.o buffer.o gps.o nmea.o uart2.o vt100.o rprintf.o timer128.o tsip.o
FUSES = -U hfuse:w:0x99:m -U lfuse:w:0xC2:m
AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
COMPILE = avr-gcc -std=gnu99 -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE)
all: main.hex
.c.o:
$(COMPILE) -c $< -lm -o $@
.S.o:
$(COMPILE) -c $< -lm -o $@
.c.s:
$(COMPILE) -S $< -lm -o $@
flash: all
$(AVRDUDE) -U flash:w:main.hex:i
fuse:
$(AVRDUDE) $(FUSES)
install: flash fuse
load: all
bootloadHID main.hex
clean:
rm -f main.hex main.elf $(OBJECTS)
main.elf: $(OBJECTS)
$(COMPILE) -lm -o main.elf $(OBJECTS)
main.hex: main.elf
rm -f main.hex
avr-objcopy -j .text -j .data -O ihex main.elf main.hex
disasm: main.elf
avr-objdump -d main.elf
cpp:
$(COMPILE) -E main.c
Best Answer
Your makefile should compile each C file into object code, then use the linker to combine the objects with libraries. You don't need
-lm
for each compiled file.In your makefile, you are using
$(COMPILE)
as both compiler and linker, which is fine for GCC, but is probably confusing matters.