Suppress warnings from library code?

I’m wondering if there’s a way to suppress warnings only from library source code. I know it’s possible to set build flags such as -w to ignore all warnings, but I want to see warnings from my own code while ignoring the spam I get from lib_deps.

Is there a way to do this without forking all my libraries and fixing their warnings?


I’d love to know if there is also, but I suspect the answer is fix the libraries. :frowning: The root issue being the Arduino IDE used to hide most of these warnings, so the library writers never saw them, so didn’t fix them (or make them! :laughing:) in the first place.

Oh, this looks like it might fit the bill…


Ah, if only library maintainers would respond to my pull requests. I’ve tried this before, with only a few polite folks bothering to respond, and even fewer kind souls taking the time to review and merge my changes.

In an ideal world, I agree this would be the best option.

1 Like

Any luck with this? .

There are global flags and per project/src. See Redirecting...

@ivankravets I tried to use

src_build_flags =
    -Wall -Wpedantic -Werror

But still, getting warnings from libs, any idea why?

Libs defined via

lib_deps =

full platformio.ini:

platform = espressif8266
board = nodemcu
framework = arduino

src_build_flags =
    -Wall -Wpedantic -Werror

extra_scripts =

lib_deps =

PlatformIO, version 4.3.1

When you run a verbose build (pio run -v, previos pio run -t clean of course), with what flags is the GCC/G++ compiler invoked when compiling library source files which throw a warning? Are these not un-settable via build_unflags?

Thank you @maxgerhardt! I’m new in platformio. I checked verbose output and the problem is: libs includes headers also contain warnings. It seems to in that case #pragma GCC diagnostic is the solution. Oooh, Arduino world :frowning:


GCC doesn’t report warnings for headers included as “system headers”.

To achieve this, you need to force platformio to include header directories with -isystem flag instead of -I. This can be done with a python script.


include_flags = []
for path in projenv["CPPPATH"]:
    if path != projenv["PROJECT_INCLUDE_DIR"]:
        include_flags.append(["-isystem", path])

    CXXFLAGS = include_flags

And then include the script in your ini.


; src_build_flags will be only applied to your src_dir
src_build_flags = -Wall -Wextra -Wpedantic -Wconversion -Werror
extra_scripts =

I tested it and it works, compiler no longer reports warnings for library code

1 Like

I couldn’t get this to work.; I get “conflicting declarations” errors. I tried several modifications to this script:

  1. Also excluding PROJECT_SRC_DIR.
  2. Removing the paths that get added to CXXFLAGS from CPPPATH, because otherwise the -I flags for those paths are still generated in addition to the custom -isystem flags.
  3. Changing INCPREFIX to -isystem, removing PROJECT_XXX_DIR from CPPATH, and adding -I flags to CXXFLAGS only for PROJECT_XXX_DIR.

It is unhappy unless everything uses -I or everything uses -isystem.

Could you send the verbose output from pio?
pio run --verbose &> logs.txt