"No such file or directory" error while building project

Hello, i just started using platformIO, and im having some issues with the Library Manager.
First i started using the blink sketch, it worked fine, then i sent some Serial messages, all good… next thing i tried was printing stuff on a small OLED screen SSD1306, for this i installed the library using the library manager Adafruit SSD1306 “by Adafruit” and while the installation went well, as soon as i try to build my project (even without including the library in the sketch) im getting this error:

In file included from .pio\libdeps\nanoatmega328new\Adafruit SSD1306\Adafruit_SSD1306.cpp:53:0:
.pio\libdeps\nanoatmega328new\Adafruit SSD1306\Adafruit_SSD1306.h:39:26: fatal error: Adafruit_GFX.h: No such file or directory

Im not sure whats going on, it just won’t build or work at all. it wold seem that its trying to look for the library in a global folder and not the project itself.
Here is my System info

PS C:\Users\RED\Documents\PlatformIO\Projects\Blink Test> pio system info
--------------------------  ----------------------------------------------------
PlatformIO Core             5.1.1a1
Python                      3.7.7-final.0
System Type                 windows_amd64
Platform                    Windows-10
File System Encoding        utf-8
Locale Encoding             cp1252
PlatformIO Core Directory   C:\Users\RED\.platformio
PlatformIO Core Executable  C:\Users\RED\.platformio\penv\Scripts\platformio.exe
Python Executable           c:\users\red\.platformio\penv\scripts\python.exe
Global Libraries            0
Development Platforms       2
Tools & Toolchains          25
--------------------------  ----------------------------------------------------

Hi Ifvideos and welcome.
Yeah, there’s a difference between installing a library for the project and installing it for global usage.
I’d recommend to install most - if not all - libs in project scope to keep concerns separated. You might want to uninstall this lib in the manager and just enter its name under lib_deps = in the platformio.ini; it will auto-download on build. See here for help on lib_deps. It makes sense to specify a lib version (because libs might change over time and if they are not kept backwards-compatible, future builds might fail - although this is unlikely for well-maintained Adafruit stuff).

This is your error. If you don’t reference the library header, PlatformIO’s library dependency finder (LDF) will not pick it up.

Do a #include <Adafruit_SSD1306.h> in your main cpp file and all will be fine.

Hey, thanks for the response. I’ve been importing them to the project, as far as i can see they removed the option to import them globally in the last version or something.

I’ll try adding it to the lib_deps to see how it goes.

If it still does not work, @maxgerhardt has a valid point about #including the stuff you need :sweat_smile:

Hello, i tried adding the #include to the .ccp file and while it fixes that issue it gives me more errors

Scanning dependencies...
Dependency Graph
|-- <Adafruit SSD1306> 2.4.3
|   |-- <Adafruit GFX Library> 1.10.4
|   |   |-- <Wire> 1.0
|   |   |-- <SPI> 1.0
|   |-- <SPI> 1.0
|   |-- <Wire> 1.0
|-- <Adafruit GFX Library> 1.10.4
|   |-- <Wire> 1.0
|   |-- <SPI> 1.0
|-- <EEPROM24LC256_512>
|   |-- <Wire> 1.0
|-- <Wire> 1.0
Building in release mode
Compiling .pio\build\nanoatmega328new\src\main.cpp.o
Archiving .pio\build\nanoatmega328new\lib434\libSPI.a
Compiling .pio\build\nanoatmega328new\lib2c1\Adafruit GFX Library\Adafruit_GrayOLED.cpp.o
Compiling .pio\build\nanoatmega328new\lib2c1\Adafruit GFX Library\Adafruit_SPITFT.cpp.o
In file included from .pio\libdeps\nanoatmega328new\Adafruit GFX Library\Adafruit_GrayOLED.cpp:20:0:
Compiling .pio\build\nanoatmega328new\lib2c1\Adafruit GFX Library\glcdfont.c.o
.pio\libdeps\nanoatmega328new\Adafruit GFX Library\Adafruit_GrayOLED.h:30:32: fatal error: Adafruit_I2CDevice.h: No such file or directory

I normally just include the SSD1306 and GFX to my projects and everything works just fine

Add adafruit/Adafruit BusIO @ ^1.7.2 to the lib_deps.

The platformio.ini should look like

[env:nanoatmega328new]
platform = atmelavr
board = nanoatmega328new
framework = arduino
lib_deps = 
    adafruit/Adafruit SSD1306@^2.4.3
    adafruit/Adafruit GFX Library @ ^1.10.4
    adafruit/Adafruit BusIO @ ^1.7.2

These are quirks of PlatformIO’s library dependency finder in this case, it’s… improvable.

1 Like

Interestingly enough, the lib_deps seems to be in order, everything shows up in the project but its not in the platformio.ini

Captura de pantalla 2021-02-02 163658

Captura de pantalla 2021-02-02 163714

“Adafruit GFX Library” is automatically included through SSD1306 but “Adafruit BusIO” not, because the library sits behind a #ifdef .. #include.. #endif barrier and PlatformIO’s LDF does not evaluate that in standard mode. It would okay if you set lib_ldf_mode = deep+ (docs) though.

Yes there’s a second barrier. Even if the folder is there, PlatformIO has to recongize the inclusion of the BusIO library in order to generate the right include flags and compile its source code. Per reason in the first paragraph that needs a quirk. As said, either per lib_deps inclusion and a reference in the main.cpp file or a more aggressive LDF setting.

1 Like

I’ll have to check this and i’ll get back to you.
Seems like this could be the issue indeed, it would be great if it included it by default but oh well.

If lib_ldf_mode = deep+ would be default (aka, evaluate all C/C++ macros in the deep chain and check whether other header files are included which need to be added in the build process), we would be increasing the compile time drastically for all users (like +3 seconds at the start of every compilation in a maybe 2 second total compilation time for Arduino Uno).

If all libs are specified in lib_deps (even the dependencies which might be behind such a #ifdef wall / check) and the library you want to use is #include-ed in the source code, it will work, and compilation will be fast.

This is just one of these quirks that you have to know in library management and how PlatformIO finds or does not find a needed library :sweat_smile:.

I tried both suggestions, they worked great and fixed the issue.
Like you said, adding it manually will probably be the best bet.

My question now is… given the error code how to find out wich one has to be included in the lib_deps

> Executing task in folder Blink Test: C:\Users\RED\.platformio\penv\Scripts\pio.exe run <

Processing nanoatmega328new (platform: atmelavr; board: nanoatmega328new; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328new.html
PLATFORM: Atmel AVR (3.1.0) > Arduino Nano ATmega328 (New Bootloader)
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr 5.1.0
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 9 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Adafruit SSD1306> 2.4.3
|   |-- <Adafruit GFX Library> 1.10.4
|   |   |-- <Wire> 1.0
|   |   |-- <SPI> 1.0
|   |-- <SPI> 1.0
|   |-- <Wire> 1.0
|-- <EEPROM24LC256_512>
|   |-- <Wire> 1.0
|-- <Wire> 1.0
Building in release mode
Compiling .pio\build\nanoatmega328new\lib2c1\Adafruit GFX Library\Adafruit_GrayOLED.cpp.o
Compiling .pio\build\nanoatmega328new\libaa2\Adafruit SSD1306\Adafruit_SSD1306.cpp.o
Compiling .pio\build\nanoatmega328new\lib9d8\EEPROM24LC256_512\EEPROM24LC256_512.cpp.o
Archiving .pio\build\nanoatmega328new\libFrameworkArduinoVariant.a
In file included from .pio\libdeps\nanoatmega328new\Adafruit GFX Library\Adafruit_GrayOLED.cpp:20:0:
.pio\libdeps\nanoatmega328new\Adafruit GFX Library\Adafruit_GrayOLED.h:30:32: fatal error: Adafruit_I2CDevice.h: No such file or directory

****************************************************************************
* Looking for Adafruit_I2CDevice.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Adafruit_I2CDevice.h"
* Web  > https://platformio.org/lib/search?query=header:Adafruit_I2CDevice.h
*
****************************************************************************

compilation terminated.
*** [.pio\build\nanoatmega328new\lib2c1\Adafruit GFX Library\Adafruit_GrayOLED.cpp.o] Error 1
==================================================================================== [FAILED] Took 3.21 seconds ====================================================================================
The terminal process "C:\Users\RED\.platformio\penv\Scripts\pio.exe 'run'" terminated with exit code: 1.

The link is right there.

Clicking on library name and going to the “Installation” tab

1 Like

Dang… you are the man!

Thank you so much for helping me take my first steps into this platform :smiley:
It is hard going from the Arduino IDE into this beast hehe but i bet it would be worth the effort.

Definitely it’s some effort, but the advantages will soon shine through. The GUI frontend is all nice and such and can definitely be worked with, just this instance is a quirk in the PlatformIO library finder. So it’s always good to know what goes on behind the curtains and how to configure the project yourself.

For that, PlatformIO’s documentation is vast and explanative. See docs.platformio.org/. For the library configuration part, this applies.

And when in doubt, this forum is always open :slight_smile:

So, i tried once again to include the library but now i added the folders manually to the lib folder, i followed all the “installation” steps, i got the SSD1306, then Adafruit GFX and gave me the error again so got the Adafruit_BusIO-master from Github and even adding it to the lib folder it just wouldn’t compile.

I finally added the lib_ldf_mode = deep line you suggested before and it compiles without issues. I was expecting this method to work better than the Library manager because thats how it works on the Arduino IDE but apparently its not the Manager but the way Platformio deals with dependencies.

Am i doing something wrong?