PlatformIO Community

Library dependency not being found

I am trying to run a demo program that came with the Adafruit_SPIFlash library. I get this error:

C:\Users\jjuni.platformio\lib\Adafruit SPIFlash_ID1643\src/Adafruit_SPIFlash.h:35:10: fatal error: SdFat.h: No such file or directory

I already #include <SD.h>. If I look in .platformio\lib\SD_ID161\utility the SdFat.h is right there.

Interestingly, if i right-click on #include “SdFat.h” in Adafruit_SPIFlash.h and select GoTo Definition, I am taken right to the desired file. So, Intellisense can find it.

This is the entire Dependency Graph:

LDF: Library Dependency Finder ->

LDF Modes: Finder ~ deep+, Compatibility ~ soft

Found 16 compatible libraries

Scanning dependencies…

Dependency Graph

|-- 3.0.1

| |-- 1.0

|-- 1.0


| |-- 1.0

Note that SdFat is not shown as a dependency of Adafruit_SPIFlash. I have even tried putting LDF in deep+ mode with no success.

I have tried putting a copy of SdFat.h in the lib folder of the project without success. I have also tried listing it in platformio.ini as lib_deps = SdFat with no success.

How can I get the compiler to find this dependent file?

And what’s the result with chain+?

Same results, unfortunately

I’ve noticed you’ve installed it in the global repository. Could you uninstall it from there again and add Adafruit SPIFlash into the lib_deps (comma-seperated)

Uninstall the library from PIO Home library manager, put a copy of the entire library in the project’s “lib” folder and reference it in lib_deps in platformio.ini? Is that correct?

Yes that’s correct. <>

Didn’t work. Still can’t find SdFat.h

Can you show the full code and platformio.ini please.

Sure. Here is the code:

#include <Arduino.h>
#include <SPI.h>
#include <SdFat.h>
#include <Adafruit_SPIFlash.h>

#if defined(__SAMD51__) || defined(NRF52840_XXAA)
  Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
    Adafruit_FlashTransport_SPI flashTransport(SS, &SPI);
    Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1);

Adafruit_SPIFlash flash(&flashTransport);

// file system object from SdFat
FatFileSystem fatfs;

void setup() {
  // Initialize serial port and wait for it to open before continuing.
  while (!Serial) {
  Serial.println("Adafruit SPI Flash FatFs Format Example");

  // Initialize flash library and check its chip ID.
  if (!flash.begin()) {
    Serial.println("Error, failed to initialize flash chip!");
  Serial.print("Flash chip JEDEC ID: 0x"); Serial.println(flash.getJEDECID(), HEX);

  // Wait for user to send OK to continue.
  Serial.setTimeout(30000);  // Increase timeout to print message less frequently.
  do {
    Serial.println("This sketch will ERASE ALL DATA on the flash chip and format it with a new filesystem!");
    Serial.println("Type OK (all caps) and press enter to continue.");
  while (!Serial.find("OK"));

  // Call fatfs begin and passed flash object to initialize file system

  // Use wipe() for no dot progress indicator.
  if ( !fatfs.wipe(&Serial) )
    Serial.println("Failed to wipe");
    while(1) delay(1);

  // Must reinitialize after wipe.
  if (!fatfs.begin(&flash)) {
    Serial.println("Error, failed to mount newly formatted filesystem!");
    while(1) delay(1);

  // Done!
  Serial.println("Flash chip successfully formatted with new empty filesystem!");

void loop() {
  // Nothing to be done in the main loop.

And here is the platformio.ini:

platform = atmelsam
board = adafruit_feather_m4
framework = arduino
debug_tool = jlink
upload_port = COM[3]
upload_protocol = jlink
monitor_speed = 115200
lib_ldf_mode = chain+

Is the wrong library. Needs SdFat_ID322 installed. This is really hard to distinguish since they are all using the same headernames, but with the SD_ID161 lib you don’t have the SdFatConfig.h which it later needs.


// implement SdFat Block Driver
#include "SdFat.h"
#include "SdFatConfig.h"

  #error ENABLE_EXTENDED_TRANSFER_CLASS must be set to 1 in SdFat SdFatConfig.h

#if FAT12_SUPPORT == 0
  #error FAT12_SUPPORT must be set to 1 in SdFat SdFatConfig.h

However, just using SdFat isn’t enough because it has hardcoded values in its config for exactly these two macros. We could try build_flags = -DFAT12_SUPPORT=1 -DENABLE_EXTENDED_TRANSFER_CLASS=1 for overriding but that gives redifinition warnings and is thus ugly. So we must download a local copy into lib/, fix the settings and then recompile. I.e.,

  • Download the SDFat zip
  • extract it into the lib/ folder as a new fodler
  • go into the SdFatConfig.h and change #define FAT12_SUPPORT 0 to 1, same for ENABLE_EXTENDED_TRANSFER_CLASS
  • add lib_deps = SdFat, Adafruit SPIFlash to the platformio.ini
  • remove all contents in the projects (hidden) .pio folder
  • recompile

The depedency graph should look something like this (pio run -v)

|-- <SdFat> 1.1.0 (C:\Users\Maxi\Documents\stackoverflow_testing\lib\SdFat-master)
|   |-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinosam\libraries\__cores__\adafruit\SPI)
|-- <Adafruit SPIFlash> 3.0.1 (C:\Users\Maxi\Documents\stackoverflow_testing\.pio\libdeps\adafruit_feather_m4\Adafruit SPIFlash_ID1643)
|   |-- <SdFat> 1.1.0 (C:\Users\Maxi\Documents\stackoverflow_testing\lib\SdFat-master)
|   |   |-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinosam\libraries\__cores__\adafruit\SPI)
|   |-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinosam\libraries\__cores__\adafruit\SPI)
|-- <SPI> 1.0 (C:\Users\Maxi\.platformio\packages\framework-arduinosam\libraries\__cores__\adafruit\SPI)

I.e the SdFat library is sourced from the local lib/ directory.

Should result in

DATA:    [          ]   3.9% (used 7684 bytes from 196608 bytes)
PROGRAM: [          ]   2.9% (used 15424 bytes from 524288 bytes)
.pio\build\adafruit_feather_m4\firmware.elf  :
 [SUCCESS] Took 7.97 seconds 

Thank you, I will try this right now.

Through all this experimentation, I have ended up with two versions of SD library already, SD_ID161 and SD_ID868, both installed using the PIO library manager. Is the ver version you are pointing to, which I will try immediately, the same as the SDFat library available through the PIO Library manager?

Should I delete both SD libraries?

Yes, the current github version of the SDFat library is exactly what PIO points to, see, “1.1.0 released 4 months ago Mar 9, 2019 5:09:38 PM”, which matches current version in github.

Yes, both SD_ID161 and SD_ID686 are the wrong libraries (Adafruit and Sparkfun Libraries), since they do not have the "SdFatConfig.h" the Adafruit_SPIFlash.h references (compare Should be deleted.

This did not yet work, sadly. I get several compiler errors. Don’t I still need the Adafruit SD library to define these types?

src\fatfs_format.cpp:27:3: error: ‘Adafruit_FlashTransport_QSPI’ does not name a type
Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS, PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
src\fatfs_format.cpp:36:26: error: ‘flashTransport’ was not declared in this scope
Adafruit_SPIFlash flash(&flashTransport);
src\fatfs_format.cpp:39:1: error: ‘FatFileSystem’ does not name a type
FatFileSystem fatfs;
src\fatfs_format.cpp: In function ‘void setup()’:
src\fatfs_format.cpp:51:20: error: no matching function for call to ‘Adafruit_SPIFlash::begin()’
if (!flash.begin()) {
In file included from src\fatfs_format.cpp:24:0:
C:\Users\jjuni.platformio\lib\Adafruit SPIFlash_ID1643/Adafruit_SPIFlash.h:98:8: note: candidate: bool Adafruit_SPIFlash::begin(spiflash_type_t)
bool begin(spiflash_type_t t);
C:\Users\jjuni.platformio\lib\Adafruit SPIFlash_ID1643/Adafruit_SPIFlash.h:98:8: note: candidate expects 1 argument, 0 provided
src\fatfs_format.cpp:55:65: error: ‘class Adafruit_SPIFlash’ has no member named ‘getJEDECID’; did you mean ‘GetJEDECID’?
Serial.print(“Flash chip JEDEC ID: 0x”); Serial.println(flash.getJEDECID(), HEX);
src\fatfs_format.cpp:65:27: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
while (!Serial.find(“OK”));
src\fatfs_format.cpp:68:3: error: ‘fatfs’ was not declared in this scope
src\fatfs_format.cpp:68:3: note: suggested alternative: ‘ffs’
Compiling .pio\build\adafruit_feather_m4\liba76\SdFat_ID322\SdCard\SdioTeensy.cpp.o
*** [.pio\build\adafruit_feather_m4\src\fatfs_format.cpp.o] Error 1

Are you sure you have lib_deps = SdFat, Adafruit SPIFlash in your platformio.ini? Adafruit_FlashTransport_SPI is defined within \Adafruit SPIFlash_ID1643\src\qspi\Adafruit_FlashTransport_QSPI.h. Analog to the FatFileSystem.

What is the dependency graph?

I think I may have introduced some typos while making and unmaking all the changes. I will try again.

Reference project at (Might need re-initialization with IDE project files, use pio init --ide=vscode etc)

1 Like

Still not working. Same errors. Going through everything in your project and comparing to mine.

When you say " use pio init --ide=vscode etc)", please tell me what “etc” is. I’m new to platform IO.

See Do you use the VSCode plugin for PlatformIO or a different IDE or just commandline?

1 Like

I will check that userguide.

I am using the VSCode plugin