Silence warnings for dependencies / external libraries?

I’ve set the -std=gnu++20 flag. Everything compiles and works fine. There are no issues with my code.

Unfortunately, there are issues within Arduino framework.

Question: can I silence those warnings, just for the Arduino code? I mean, I still want to see those warnings for my code, so I don’t make mistakes, but I cannot (I’m not willing to) modify external libraries to fix their issues.

Same goes with any other flag, I guess.

I wish I could enable -Wextra, etc, but then I get too much junk from dependencies…

Maybe it could be filtered out from the output somehow? Showing issues only for paths of my code, ignoring the rest?

I’m trying to set some flags just for my code, without setting them to frameworks or external libraries. No success.

Let’s take -Wpedantic… Multiple issues show up for the framework code, for example:

/Users/dada/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/esp8266_undocumented.h:254:2: warning: extra ';' [-Wpedantic]
 254 | };
     |  ^

All 4 methods I’ve tried result in the warning(s) like the one above:

  • Add the flag to build_flags.
  • Add the flag to build_src_flags.
  • I’ve tried to create POST extra script, it fails for both env and projenv:
    ; platformio.ini
    extra_scripts = post:scripts/
    # scripts/
    from SCons.Script import Import
    # I've tried both `env` and `projenv` - same result
  • I’ve tried to create a build middleware to add the flag(s) in an extra script. No success:
    ; platformio.ini
    extra_scripts = pre:scripts/
    # scripts/
    from SCons.Node.FS import File as SConsFile
    from SCons.Script import Import
    from SCons.Script.SConscript import SConsEnvironment
    def maybe_modify_node(env: SConsEnvironment, node: SConsFile):
        files_to_add_flags = [
        if node.get_internal_path() in files_to_add_flags:
            return env.Object(
                CXXFLAGS=env['CXXFLAGS'] + ['-Wpedantic']
        return node    
    env: SConsEnvironment

I’ve really spent too much time trying to figure out / GUESS how to do it / reading the python spaghetti… Is it really that hard to set a freakin flag to a file I want?

How do I add a build flag to only MY code? My code being in src and lib dirs, excluding framework and external libraries downloaded by PIO?

Build options — PlatformIO latest documentation lists both build_flags and build_src_flags.

but will be applied only for the project source files in the src_dir directory.


nope, as i said, i’ve tried both – framework files still get compiled with the flag, throwing warnings

That’s a tricky one. As soon as you pull in code from the header files of the framewrok in your own code, they’re subject to scanning. #include is just a copy-paste directive after all.

Warnings from the framework includes need to be supressed by turining -I flags in -isystem flags…

But at least it does not report these warnings in the .c/.cpp sources of the framework then, which is a step forward.

1 Like

When I create a minimal project with

platform = espressif8266@4.2.0
board = nodemcuv2
framework = arduino
build_unflags = -std=gnu17
build_flags =  -std=gnu++20
build_src_flags = -Wall -Wextra -Wpedantic

and a src/main.cpp that just has

#include <Arduino.h>

void setup() {}
void loop() {}

in it, indeed it throws tons of errors.

In file included from C:\Users\Max\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/esp8266_peri.h:28,
                 from C:\Users\Max\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/Arduino.h:39,
                 from src\main.cpp:1:
C:\Users\Max\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/esp8266_undocumented.h:99:12: warning: ISO C++ prohibits anonymous structs [-Wpedantic]
   99 |     struct {
      |            ^
C:\Users\Max\.platformio\packages\framework-arduinoespressif8266\cores\esp8266/esp8266_undocumented.h:254:2: warning: extra ';' [-Wpedantic]
  254 | };
      |  ^

now I add

extra_scripts =

with content

from pathlib import Path
Import("env" ,"projenv")

platform = env.PioPlatform()
FRAMEWORK_DIR = Path(platform.get_package_dir("framework-arduinoespressif8266"))
framework_includes = list()
filtered_cpppath = list()
# apply these changes to current working env, the project env and the global env
for e in (env, projenv, DefaultEnvironment()):
    for p in e["CPPPATH"]:
        # is the current include path inside the framework directory?
        if FRAMEWORK_DIR in Path(p).parents:
    e.Append(CCFLAGS=[("-isystem", p) for p in framework_includes])

and the warnings are gone.

In the verbose build output, it can now be see that what was before

xtensa-lx106-elf-g++ -o .pio\build\nodemcuv2\src\main.cpp.o -c -std=gnu++20 -fno-rtti -std=gnu++17 -fno-exceptions -Os -mlongcalls -mtext-section-literals -falign-functions=4 -ffunction-sections -fdata-sections -Wall -Werror=return-type -free -fipa-pta -Wall -Wextra -Wpedantic -DPLATFORMIO=60107 -DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_NODEMCU_ESP12E -DF_CPU=80000000L -D__ets__ -DICACHE_FLASH -D_GNU_SOURCE -DARDUINO=10805 -DARDUINO_BOARD="PLATFORMIO_NODEMCUV2" -DARDUINO_BOARD_ID="nodemcuv2" -DFLASHMODE_DIO -DLWIP_OPEN_SRC -DNONOSDK22x_190703=1 -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DVTABLES_IN_FLASH -DMMU_IRAM_SIZE=0x8000 -DMMU_ICACHE_SIZE=0x8000 -U__STRICT_ANSI__ -Iinclude -Isrc -IC:\Users\Max.platformio\packages\framework-arduinoespressif8266\tools\sdk\include -IC:\Users\Max.platformio\packages\framework-arduinoespressif8266\cores\esp8266 -IC:\Users\Max.platformio\packages\toolchain-xtensa\include -IC:\Users\Max.platformio\packages\framework-arduinoespressif8266\tools\sdk\lwip2\include -IC:\Users\Max.platformio\packages\framework-arduinoespressif8266\variants\nodemcu src\main.cpp

Is now

xtensa-lx106-elf-g++ -o .pio\build\nodemcuv2\src\main.cpp.o -c -std=gnu++20 -fno-rtti -std=gnu++17 -fno-exceptions -Os -mlongcalls -mtext-section-literals -falign-functions=4 -ffunction-sections -fdata-sections -Wall -Werror=return-type -free -fipa-pta -Wall -Wextra -Wpedantic -isystem C:\Users\Max.platformio\packages\framework-arduinoespressif8266\tools\sdk\include -isystem C:\Users\Max.platformio\packages\framework-arduinoespressif8266\cores\esp8266 -isystem C:\Users\Max.platformio\packages\framework-arduinoespressif8266\tools\sdk\lwip2\include -isystem C:\Users\Max.platformio\packages\framework-arduinoespressif8266\variants\nodemcu-DPLATFORMIO=60107
-DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_NODEMCU_ESP12E -DF_CPU=80000000L -D__ets__ -DICACHE_FLASH -D_GNU_SOURCE -DARDUINO=10805 -DARDUINO_BOARD="PLATFORMIO_NODEMCUV2" -DARDUINO_BOARD_ID="nodemcuv2" -DFLASHMODE_DIO -DLWIP_OPEN_SRC -DNONOSDK22x_190703=1 -DTCP_MSS=536 -DLWIP_FEATURES=1 -DLWIP_IPV6=0 -DVTABLES_IN_FLASH -DMMU_IRAM_SIZE=0x8000 -DMMU_ICACHE_SIZE=0x8000 -U__STRICT_ANSI__ -IC:\Users\Max.platformio\packages\toolchain-xtensa\include -Iinclude -Isrc -IC:\Users\Max.platformio\packages\toolchain-xtensa\include src\main.cpp

So all framework includes were changed from -I to -isystem, supressing the errors coming from those files.

Other paths from user libraries and the toolchain are unaffected.

1 Like

CFLAGS are for C code, CXXFLAGS are for C++ code → what are CCFLAGS?

EDIT: nvm:

General options that are passed to the C and C++ compilers.

  1. you “take” the paths from CPPPATH
  2. “partition” them into framework and non–framework paths
  3. replace CPPPATH with only non–framework paths
  4. add framework paths to CCFLAGS

This is what I don’t understand: wouldn’t it be better to add framework paths to CXXFLAGS? Since the origin CPPPATH would not (would it?) give C paths anyway, just C++ paths?

I only ever saw CPPPATH and never a CPATH variable, so I assume all include directories are classically stored there – but I’m open to being corrected by SCons docs.

Haha, OK :smiley:

It works both ways, in my case anyway.

OK, so with your method, I’ve managed to silence issues from the framework package, being framework-arduinoespressif8266: ``-Wpedantic` for `native` and `nodemcu` envs · MacDada/DnWiFiDoorLock@6db069f · GitHub

In the process, I’ve learnt that while framework-arduinoespressif8266 is a “package”, the libraries like ArduinoFake are not → so the method does not work with them…

I thought this would be easy, as there is a build_src_flags option, that I hoped would let me set the flags for my code, while skipping the dependency–libraries → it doesn’t work like that: `build_src_flags` impacts not only `src_dir` but also dependencies? · Issue #4667 · platformio/platformio-core · GitHub

Any idea how to resolve this issue temporarily? Until build_src_flags gets fixed? Or permanently, if the issue is “resolved” as “not a bug, but a feature”? :wink:

Hello, so I ran into a similar issue today. I am using CLion with the PlatformIO plugin (and pio on the command line) and I have an issue with warnings from dependencies / external libraries.

What I would like is to only have warnings from my own source code (./src and - if possible - the ./lib/* folders).

I am not very well versed in Python, but the script does not work for me (it supposedly even has syntatical issues, that I cannot resolve if interpreting the Python script using Python 3.11). Besides the solution seems to introduce Python as a dependency - which can be an issue if using a CI pipeline (though I assume I’d just have a target without any Python scripts in it for a CI pipeline).

I am working on an Arduino Zero and the warnings I get (after upping the version from gnu++11 to gnu++17 in order to not have warnings regarding inline modifiers) come from multiple packages (framework-cmsis, ArduinoLog, FastLED, framework-arduino-samd, possibly others).

Can anyone help me find a way to ignore warnings from those libraries? In particular I’d like to have extensive warnings etc. on my own code, but not the libraries nor the included headers (and sources) of said libraries.