[英]Makefile for avr-gcc “no such file or directory”
I'm new to makefile, and I tried to modify one I had by a teacher.我是 makefile 的新手,我尝试修改老师的一个。
My goal is to link "i2cMaster.S" so I did this:我的目标是链接“i2cMaster.S”所以我这样做了:
export CC = avr-gcc
export MCU = atmega328p
export TARGET_ARCH = -mmcu=$(MCU)
export CFLAGS = -Wall -I. -DF_CPU=16000000 -Os #-g
export LDFLAGS = -g $(TARGET_ARCH) -lm -Wl,--gc-sections # -Os
TARGET = main
TERM = /dev/ttyUSB0
CPPFLAGS = -mmcu=$(MCU)
PGID = arduino
PGMER = -c $(PGID) -b 57600 -P $(TERM)
PGMERISP = -c $(PGID) -b 115200 -P $(TERM)
ARVDUDECONF= -C /usr/local/arduino/arduino-0022/hardware/tools/avrdude.conf
export DUDE = /usr/bin/avrdude -F -v -p $(MCU) $(AVRDUDECONF)
C_SRC = $(wildcard *.c)
A_SRC = i2cmaster.S
OBJS = $(C_SRC:.c=.o) $(A_SRC:.S=.o)
all: $(TARGET).hex
clean:
rm -f *.o
%.o:%.c
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $(@F)
%.o:%.S
$(CC) -S $(CPPFLAGS) $(CFLAGS) $< -o $(@F)
%.elf: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS)
%hex: %.elf
avr-objcopy -j .text -j .data -O ihex $(TARGET).elf $(TARGET).hex
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 -O ihex $(TARGET).elf eeprom.hex
upload: $(TARGET).hex
stty -F $(TERM) hupcl # reset
$(DUDE) $(PGMER) -U flash:w:$(TARGET).hex
# $(DUDE) $(PGMERISP) -U flash:w:$(TARGET).hex
size: $(TARGET).elf
avr-size --format=avr --mcu=$(MCU) $(TARGET).elf
I added the %.o:%.S
target, but it seems not to work.我添加了
%.o:%.S
目标,但它似乎不起作用。 When I call make all
, I have the following error:当我调用
make all
时,出现以下错误:
avr-gcc: error: i2cmaster.o: No such file or directory.
I think the error is pretty obvious, bit I can't find out where it comes from.我认为错误很明显,有点我不知道它来自哪里。
Your command to assemble "i2cmaster.S" does not assemble, because you use the option -S
:您组装“i2cmaster.S”的命令不会组装,因为您使用了选项
-S
:
%.o:%.S
$(CC) -S $(CPPFLAGS) $(CFLAGS) $< -o $(@F)
Instead use the option -c
:而是使用选项
-c
:
%.o:%.S
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $(@F)
Please call GCC to help you:请致电 GCC 为您提供帮助:
gcc --help
And it will tell:它会告诉你:
-c Compile or assemble the source files, but do not link.
-S Stop after the stage of compilation proper; do not assemble.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.