3

I've been looking to modify the build flags under Arduino's IDE 1.x, or even the Arduino CLI (which I haven't used but am willing to adopt) such that I can undefine -std=gnu++11 and instead define -std=gnu++14

I found a question related to this which gives me almost what I need:

Arduino 1.0.6: How to change compiler flag?

But it only shows how to add flags, not to remove them. I found another related post about changing arduino to GNU C++17 but the answer was it's not possible.

In this case, I know it's possible, as I do it in Platform IO in order to use the htcw_gfx library. It works great on most platforms that will run GFX reasonably anyway.

But I just don't know how to fiddle with Arduino to get it to dance the way I need to.

Any help would be greatly appreciated.

  • You didn't say which version of the Arduino IDE you're using. I assume latest 1.x since you chased a link for 1.x – lurker Apr 03 '22 at 18:23
  • Thanks! I edited. I totally forgot there's a new version of the IDE. To be honest I use platformIO but i write libs and some of them require C++14 so I'm trying to figure this out so i can help people use what I wrote from Arduino IDE instead of just PIO – honey the codewitch Apr 03 '22 at 19:46
  • Yeah I would think somewhere in the bowels of the arduino-cli tools there's an actual call to a compiler with options. You might be able to modify it at that level. But from what I've read, out of the box, the Arduino development tools are fairly restrictive, maintaining a very controlled development environment which is convenient for hobbyists who mostly dabble in C/C++ programming. – lurker Apr 03 '22 at 20:52
  • Turns out the answer was hiding in the post you linked in one of the lower rated answers! – ljden Jul 16 '22 at 11:04

1 Answers1

2

You can modify the default compile flags in the hardware/arduino/avr/platform.txt file.

$ grep -n "std" hardware/arduino/avr/platform.txt
23:compiler.c.flags=-c -g -Os {compiler.warning_flags} -std=gnu11 -ffunction-sections -fdata-sections -MMD -flto -fno-fat-lto-objects
28:compiler.cpp.flags=-c -g -Os {compiler.warning_flags} -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto

For some linux systems the following would work to automatically do this:

dirname $(realpath $(which arduino)) | xargs -I{} sed -i "s/\(std=gnu++1\)1/\14/" {}/hardware/arduino/avr/platform.txt

But this is not very portable, and will not work if the user has installed Arduino with Snap (as snap has these files mounted RO).

Sources:

ljden
  • 352
  • 1
  • 11