I like to play with C++. Unfortunately, toolchain-atmelavr that is used in platfromio is old and some features are unsupported (even if it is c++17).
For example:
template<volatile uint8_t& a>
class A {};
template<volatile uint8_t& a>
class B: public A<a> {};
results in:
error: expression 'a' has side-effects
class B: public A<a> {};
However, gcc 9 doesn’t have this issue.
Is it any way to use system gcc instead of platformio package?
I’m using MacOs and brew.
The next code works:
template<volatile uint8_t& a>
class A {};
template<uint8_t& a>
class B: public A<a> {};
It is totally different meaning.
The highest version in the registry is 7.3.0 (PlatformIO Registry).
If you have Windwos or Linux, please download the binaries from AVR-GCC 12.1.0 for Windows 32 and 64 bit | Zak’s Electronics Blog ~*, extract the folder somewhere. If you have Mac, find where macports installed avr-gcc (which per this should also be 12.1.0) with e.g. which avr-gcc
if it’s installed globally and duplicate the whole toolchain folder somewhere.
Then copy the package.json
from <home folder>/.platformio/packages/toolchain-atmelavr/
into that extracted folder at the same location, change the “version” field to 3.120100.220725
and add
platform_packages =
toolchain-atmelavr@symlink://<full path to the extracted toolchain folder here>
to the platformio.ini
. (Full path on Mac will have a /
at the front, will result in symlink:///User/...
, which is perfectly fine.)
This way I could use a local AVR-GCC 12 installation on Windows just a while ago to test things out.
The C++ STL implementation is still extremely bad and missing large chunks – but at least C++ language wise, the newer versions should be better…
Thank you. Even if it’s a dirty trick it can work.
Of course, I have a new version of GCC.
I was able to solve this issue by changing the code a little bit. However, I missed some features like concepts and advanced constexp.
And I decided to not use STL. It looks too complicated. At least, I don’t want to use dynamic memory allocation and exceptions.
G++ works very well. Classical blink and button can be compiled without using RAM at all.