如何解决avr-gcc 的 Makefile“没有这样的文件或目录”
我是 makefile 的新手,我试图修改我老师提供的一个。
我的目标是链接“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
我添加了 %.o:%.S
目标,但它似乎不起作用。当我调用 make all
时,出现以下错误:
avr-gcc: error: i2cmaster.o: No such file or directory.
我认为错误很明显,有点我不知道它来自哪里。
解决方法
你的汇编“i2cmaster.S”命令没有汇编,因为你使用了选项-S
:
%.o:%.S
$(CC) -S $(CPPFLAGS) $(CFLAGS) $< -o $(@F)
改为使用选项 -c
:
%.o:%.S
$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $(@F)
请致电 GCC 来帮助您:
gcc --help
它会告诉:
-c Compile or assemble the source files,but do not link.
-S Stop after the stage of compilation proper; do not assemble.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。