Compiler rules for AVR seems to miss some informations for C++ and ar call is not working.
ChibiOS 21.11.2
Compiler: avr-gcc 5.4.0
Platform and board: atmeg328p - arduino nano - demo RT
C++ compilation does not work if it includes AVR hardware. For instance:
Code: Select all
main.cpp:20:22: error: ‘IOPORT4’ was not declared in this scope
Moreover, the make lib is not working as expected:
Code: Select all
avr-ar: two different operation options specified
This report could be split in two but since it is related to only one file I reported once. Tell me if this is a problem.
Following is a patch that resolve the bugs in AVR GCC rules.mk file. For C++ flags I mostly copy/paste C flags and only update the required standard.
Code: Select all
--- vanilla/ChibiOS_21.11.2/os/common/ports/AVR/compilers/GCC/rules.mk 2017-09-16 16:02:09.000000000 +0200
+++ ChibiOS_21.11.2/os/common/ports/AVR/compilers/GCC/rules.mk 2022-08-25 20:03:07.339113729 +0200
@@ -81,6 +81,12 @@
CFLAGS += -std=gnu11 -mrelax -fdata-sections -ffunction-sections
CFLAGS += -Wundef -MMD -MP #-MF
+CPPFLAGS = $(MCFLAGS) -I. -gdwarf-2 $(CDEFS) $(OPT) -funsigned-char
+CFLAGS += -funsigned-bitfields -fpack-struct -fshort-enums $(CWARN)
+CFLAGS += -Wa,-adhlns=$(LSTDIR)/$(notdir $(<:.c=.lst)) $(DEFS)
+CFLAGS += -std=gnu++11 -mrelax -fdata-sections -ffunction-sections
+CFLAGS += -Wundef -MMD -MP #-MF
+
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns: create listing
@@ -264,7 +270,7 @@
lib: $(OBJS) $(BUILDDIR)/lib$(PROJECT).a
$(BUILDDIR)/lib$(PROJECT).a: $(OBJS)
- @$(AR) -r $@ $^
+ @$(AR) $@ $^
@echo
@echo Done