C++ on the AVR port Topic is solved

ChibiOS public support forum for topics related to the Atmel AVR family of micro-controllers.

Moderator: tfAteba

Post Reply
mikenick42
Posts: 28
Joined: Tue Mar 10, 2015 4:49 pm
Been thanked: 1 time

C++ on the AVR port

Post by mikenick42 »

Has anyone had any luck with C++ on the AVR port of ChibiOS? I know the STM port can do it but when I try renaming main.c and moving it in the Makefile I get:

Code: Select all

/usr/lib/avr/include/avr/io.h:623:6: warning: #warning "device type not defined" [-Wcpp]
 #    warning "device type not defined"


It looks like __AVR_ATmega328P__ isn't being defined for some reason.

Is it even worth using C++? I'm mainly interested in it because it makes encapsulation more convenient. What I want should be possible if I'm careful about how and where I declare things in C, but is a little cleaner in C++.
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: C++ on the AVR port

Post by tfAteba »

Hello,

No I have never try to compile AVR code with C++ compiler.
davidli
Posts: 6
Joined: Fri Jun 11, 2021 7:15 am

Re: C++ on the AVR port

Post by davidli »

Maybe it only works under windows?
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: C++ on the AVR port

Post by tfAteba »

Hello Davidli,

No it is not related to OS that you use.

Can yous share me the modification that you made in ChibiOS so that I can try to help.
User avatar
tfAteba
Posts: 551
Joined: Fri Oct 16, 2015 11:03 pm
Has thanked: 91 times
Been thanked: 50 times

Re: C++ on the AVR port

Post by tfAteba »

Hello Davidli,

I have take some time to look how to use C++ with AVR MCU.
As I said in this thread https://forum.chibios.org/posting.php?mode=reply&f=35&t=6125,
I have create a demo under demos/AVR/RT-ARDUINO-UNO-G++ to show how we can use C++.

It looks like __AVR_ATmega328P__ isn't being defined for some reason.

It was due to the lac of CPP flags in the rules.mk file that is use to build our sources.

Is it even worth using C++? I'm mainly interested in it because it makes encapsulation more convenient. What I want should be possible if I'm careful about how and where I declare things in C, but is a little cleaner in C++.

You can now use C or C++ 8-) .
Post Reply