Skip to main content
2 of 4
Add more details
Alex 75
  • 121
  • 4

include directive for external libraries

I added the Adafruit_GFX_Library to my Windows. I used Arduino IDE, Tools > Manage Libraries > Install.
In preferences, Sketchbook location is set to "d:\Alex\Hobbies\Electronic\Learning Arduino\Source", so it created the "libraries" folder and the "libraries/Adafruit_GFX_Library" with the Adafruit_GFX.h file and all the rest.

In the sketch I can use "#include <Adafruit_GFX.h>" and it works for Arduino IDE.
The problem is with Visual Studio Code and the Arduino extensions.

I have added "${workspaceFolder}/Source/libraries/Adafruit_GFX_Library" to the "includePath" list of the c_cpp_properties.json file.
It solved the problem with VS Code Intellisense that cannot find the library otherwise. Good.
Now I have the same problem ("No such file or directory") when I try to Upload (= build + write to Arduino board), it says: "fatal error: Adafruit_GFX.h: No such file or directory" .

I tried to use a relative path: #include "../libraries/Adafruit_GFX_Library/Adafruit_GFX.h" but it does not wotk neither (Intellisense is fine):
"fatal error: ../libraries/Adafruit_GFX_Library/Adafruit_GFX.h: No such file or directory".

What path should I use ?

[EDIT 1]
I add the fiull path too in the includePath:

"${workspaceFolder}/Source/libraries/Adafruit_BusIO",
"${workspaceFolder}/Source/libraries/Adafruit_GFX_Library",
"${workspaceFolder}/Source/libraries/Adafruit_PCD8544_Nokia_5110_LCD_library",
"d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_BusIO",
"d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_GFX_Library",
"d:/Alex/Hobbies/Electronic/Learning Arduino/Source/libraries/Adafruit_PCD8544_Nokia_5110_LCD_library"

Both them works... because without it the Intellisense complains about Adafruit_GFX.h not found.
Adding them it complains about Wire.h and SPI.h (not smart enough to look inside the "src" folders), so I also add them:

"C:\\Users\\Alex\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\libraries\\Wire\\src",
"C:\\Users\\Alex\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.6\\libraries\\SPI\\src",

and Intellisense works!

But not the build (Adafruit_GFX.h not found!).

Alex 75
  • 121
  • 4