Library include header file not found

I am relatively new to PlatformIO. I have done a couple of simple projects to learn the basics. I am now working on a more complex project and have imported several Adafruit libraries which also included several dependency libraries as well. The project now has 23 libraries listed in the lindeps section of the explorer. The project will not compile; it returns “fatal error: Adafruit_SPIFlash.h: No such file or directory.”

I have examined the platform.ini file and it includes the line “adafruit/Adafruit SPIFlash@^3.4.1” in lib_deps. I also examined the c_cpp_properties.json file and it includes the line “/Users/Bob/Documents/PlatformIO/Projects/RobotTechDemo/.pio/libdeps/adafruit_feather_m4/Adafruit SPIFlash/src” in the include path. In the explorer, the supposed missing file is indeed located at the path contained in the c_cpp_properties.json file.

Appreciate any help pointing me in the right direction to resolve this.

The important part is whether Adafruit SPIFlash appears in the Dependency graph outputted at the start of compilation. What does it look like? The libraries may be generally declared but if the library dependency finder (LDF) doesn’t detect its usage, it won’t be included in the build process properly.

Doing a #include <Adafruit_SPIFlash.h> in the src/main.cpp file might also solve your problem.

Thanks Max for your input. I examined the dependency graph and the Adafruit SPIFlash library is not included as a dependency of the Adafruit Sensor Calibration library (or any where else). Seems like it should be included as a dependency under the Sensor Calibration library since this is where the include statement for Adafruit_SPIFlash.h appears.

I added an include statement for the Adafruit_SPIFlash.h in main.cpp but it did not resolve the problem. However, the Adafruit SPIFlash library did show up in the dependency graph at the top level as you would expect.

How is the dependency graph created? What is the data source the compiler uses to create it?

Thanks in advance for any more insight.

It’s created differently according to the selected LDF mode as selected by lib_ldf_mode.

If th dependency doesn’t show up in the hierarchy where it’s supposed to be, please first set a more aggressive LDF mode, e.g.

lib_ldf_mode = chain+

in the platformio.ini.

If this still does not help, please post the platformio.ini and minimal code that reproduces the issue.

I studied the section on the LDF and tried the chain+ and the root/root+ options with no success.

I have created a new simple project with only the Adafruit Sensor Calibration Library installed. This library includes as one of its dependencies, the Adafruit SPIFlash library. main.cpp is just the default Arduino framework file with empty setup() and loop() functions. I added an include statement for the Adafruit_Sensor_Calibration.h file.

When compiled I get the same error; Adafruit_SPIFlash.h not found even though it is in the explorer. Also, Adafruit_SPIFlash does not show up in the dependency graph.

I am not sure how to “post” a copy of the .ini and main.cpp files (I’m new to this). I just copied and pasted them below.

platform = atmelsam
board = adafruit_feather_m4
framework = arduino
lib_ldf_mode = chain+
lib_deps = adafruit/Adafruit Sensor Calibration@^1.1.2

#include <Arduino.h>
#include <Adafruit_Sensor_Calibration.h>
void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:

Aah yes I remember again. You’re doing everything right, PlatformIO has pretty sure a bug there that currently prevents it from detecting the inclusion by not seeing that a define exists which lights up certain code triggering the inclusion…

The exact same was also reported at Failure building Adafruit Sensor Calibration Library - can't find Adafruit_SPIFlash.h

A bug report was opened but it was said that it isn’t a bug after all, to which I disagree, but haven’t further had the time to investigate and prove the opposite.

The workaround is valid exactly as in the referenced post. We make sure PIO sees the section

as activated by defining EXTERNAL_FLASH_DEVICES to the same value is the board header file itself would

so adding


to the platformio.ini will also solve your problem here.

OK, this works. Since this builds in the Arduino environment, I would agree that it sounds like a possible bug. Thanks again for your help.

Sorry for bringing it up аgain after a long time

I’m encountering the same problem and not able to solve with explicit include in the main or with definition of EXTERNAL_FLASH_DEVICES.

here is my config:

platform = nordicnrf52
board = adafruit_cplaynrf52840
framework = arduino
lib_ignore = Adafruit BluefruitLE nRF51
lib_ldf_mode = chain+
lib_deps = 
	adafruit/Adafruit LED Backpack Library@1.5.0
	adafruit/Adafruit Circuit Playground@^1.12.0
	adafruit/Adafruit Unified Sensor@^1.1.14
    adafruit/SdFat - Adafruit Fork@^2.2.3
    adafruit/Adafruit NeoPixel@^1.12.0
    adafruit/Adafruit AHRS@^2.3.5
    adafruit/Adafruit BusIO@^1.15.0
    adafruit/Adafruit GFX Library@^1.11.9
    adafruit/Adafruit SPIFlash@^4.3.4

build_flags = -D ENV_EMPTY
build_src_filter = +<*> -<examples> -<examples/*> -<test> -<test/*> -<tests> -<tests/*> -<test_*> -<main-*> +<main-empty.cpp>

and the source file:

#include <Adafruit_CircuitPlayground.h>

void setup() {

void loop() {

Appreciate help or ideas.