I am having issues when keeping libraries in a location that is not the default for VSCode/PlatformIO. I have built a minimal VS Code workspace in an attempt to better understand the problem and would appreciate any comments you may have.
As I understand it, VSCode/PlatformIO, given an #include<myfile.h> will search for that file based upon the locations in the current workspace’s “c_cpp_properties.json” file. The VSCode Intellisense also functions by using the locations of the “.h” files given in “c_cpp_properties.json”. Therefore, if the “.h” header files are all present in a folder that is represented in the “c_cpp_properties.json” file, they should be able to be found.
Given my minimal test project of:
#include <Arduino.h>
#include <Keypad.h> /An arbitrary library for testing/
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
…and placing the Keypad library, which contains the required Keypad.h files, into unique location other than the default platformIO libraries location, and updating c_cpp_properties.json file appropriately, I would expect the compilation to succeed. It fails with
src\main.cpp:2:20: fatal error: Keypad.h: No such file or directory
Here is a section of the c_cpp_properties.json file, with the modifications I made for the addition of the Keypad library…
“includePath”: [
…several lines deleted for brevity…
“C:/Users/sam/.platformio/packages/tool-unity”,
“Z:/CodeArchive/ArduinoLibraries/Keypad/src”,
“”
],
and…
“browse”: {
“limitSymbolsToIncludedHeaders”: true,
“path”: [
…several lines deleted for brevity…
“C:/Users/sam/.platformio/packages/framework-arduino-avr/libraries/Wire/src”,
“C:/Users/sam/.platformio/packages/tool-unity”,
“Z:/CodeArchive/ArduinoLibraries/Keypad/src”,
“”
]
Adding the absolute path “Z:/CodeArchive/ArduinoLibraries/Keypad/src” from the Keypad library folder to the list of includePath(s) in c_cpp_properties.json cures the “squiggle” over the #include<Keypad.h> line in the IDE, however the compilation still fails to find the file.
Adding the absolute path to the Browse section of c_cpp_Properties.json has no effect on the outcome.
However, If I use an absolute path in the #include<>, such as #include “Z:/CodeArchive/ArduinoLibraries/Keypad/src/Keypad.h” then the compilation will succeed without errors.
Am I missing another setting that must be configured to point to my libraries when they are placed in a non-default location?