PlatformIO Community

#include statements ignored, overridden by connected libraries

Hello all,
I have noticed that PIO ignores #include statements. I have added (connected?) several libraries to my project that I intend to implement in the future. They are not yet configured, so I have commented them out as below. However, during compilation, PIO includes these libraries (which throw errors that prevent compilation).

Is there a setting that I can use to make PIO respect this, please?

#include <Arduino.h>
#include <SPI.h>
#include <FS.h>
//#include <FreeRTOS.h>
//#include <lvgl.h>

I suspect your problem is that PlatformIO will attempt to compile any C/C++ source files that it finds in the src and/or lib/* directories. My advice would be, don’t put incomplete libraries into lib if they have any C/C++ source files p[resent.



Thanks Norm, I appreciate you taking the time to read my question and reply. Though I would say it doesn’t address the issue.

All the best,

Ok, lets try again. :wink:

I’m assuming that the two libraries you have commented out are being included?

Stupid question, but did you save the source file after commenting out the two header file includes? (Sorry, but I had to ask!)

I’ve created a project for an Uno, added a test library with only the header file present – lib/test/test.h and the contents are simply:

#ifndef TEST_LIB
#define TEST_LIB

#error "OOPS! Test library header included in error."


And a source file in src/main.cpp:

#include "Arduino.h"
//#include "test.h"

void setup() {

void loop() {

And no matter what I do, other than not saving the file with the comment markers on the #include, the header file is never compiled.

Can you try again with your project,. but run a verbose build please? If you are running on the command line:

pio run -t clean
pio run -v

If in VSCode:

  • Click the ant/alien head in the far left toolbar.
  • Open “Project Tasks” drop down.
  • Open “Uno” dropdown. (Or whichever board you are using.)
  • Open “General” dropdown.
  • Select “clean” option.


  • Open the “advanced” dropdown.
  • Select “verbose build” option

If you can capture the output, we should be able to see the problem in the listing.

Post it here wrapped in three backticks to get proper code formatting.