AVR - C++ and lib generation no functionnal Topic is solved

Report here problems in any of ChibiOS components. This forum is NOT for support.
Philippe Leduc
Posts: 1
Joined: Thu Aug 25, 2022 7:06 pm
Been thanked: 2 times

AVR - C++ and lib generation no functionnal  Topic is solved

Postby Philippe Leduc » Thu Aug 25, 2022 7:22 pm

Hello,

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

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: AVR - C++ and lib generation no functionnal

Postby tfAteba » Sun Nov 20, 2022 11:12 pm

Hi Philippe,

Thanks for you feed back and the patch.

Sorry I'm not use to look at general bug reports that why I did not see your message. A usually look to the AVR support.

I will make some test with you patch, and your set up.

I never test c++ in Arduino side, so it will be interesting to do that.

You will be notify as soon as I will give a try :)
regards,

Theo.

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: AVR - C++ and lib generation no functionnal

Postby tfAteba » Wed Nov 23, 2022 12:43 am

Hi Philippe,

Compiler rules for AVR seems to miss some informations for C++ and ar call is not working.

Yes it was just CPP flags that was missing. Now it is ok in ChibiOS/trunk, I have just commited a fix for that.

Note that there is a problem with you patch (you are mixing C and CPP flags):
+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

Those must be CPP flags.

I still need to look at the make lib.

But the C++ compilation is now using the AVR Hardware.

I have create a C++ demo under demos/AVR/RT-ARDUINO-UNO-G++ in the trunk.
regards,

Theo.

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: AVR - C++ and lib generation no functionnal

Postby tfAteba » Wed Nov 23, 2022 7:19 pm

Hi all,

I still need to look at the make lib.

Thanks for the patch in the library generation side.

So every thing have been fixed and committed in trunk.
regards,

Theo.


Return to “Bug Reports”

Who is online

Users browsing this forum: No registered users and 11 guests