-1

I have folder "I2C AtMega32":

folder tree

and I have my simply Makefile:

all: main.hex program clean

main.o: main.cpp BMP280_driver-master\bmp280.c
    avr-gcc -Wall -Os -mmcu=atmega32 -c $< -o $@

main.elf: main.o
    avr-gcc -Wall -Os -mmcu=atmega32 -o main.elf main.o

main.hex: main.elf
    avr-objcopy -j .text -j .data -O ihex main.elf main.hex
    avr-size --format=avr --mcu=atmega32 main.elf

program:
#program uC

.PHONY: clean
clean:
    rm main.o main.elf

During the makefile working there is some errors:

some errors here

Why it is no working?

Mavimix
  • 119
  • 1
  • 8
  • 2
    Having target all build clean is a huge red flag. Don't. Second, your main.o rule doesn't build bmp280.c. You should build a separate bmp280.o target for that. Read the docs on built-in rules and pattern rules. – Andreas May 26 '22 at 15:02
  • 1
    Please don't post text as images. You should copy and paste it and format it as code. – David Grayson May 26 '22 at 17:50

1 Answers1

0

The main issue is it looks like you are trying to compile two different compilation units into one object file. I would be surprised if GCC supports that, since I've never seen it before. Compile an object with gcc for each C source file, then compile an object with g++ for each C++ source file, then link them all together.

Also note that $< is just the name of the first prerequisite (main.cpp) so you never even attempted to compile the bmp280 code. Pay attention carefully to the commands your Makefile is running when you want to debug your build.

By the way, the all target should just build your HEX file. You can run make program or make clean separately to perform those tasks, and the program target should of course depend on main.hex.

David Grayson
  • 84,103
  • 24
  • 152
  • 189