When I use Visual Studio Code and try to #include a library a get errors that the library can’t be found. I have tried both, tried using the Particle’s extension to “Install a library”, which finds the library online and incorporates it into the IDE, but I still get errors on the IDE finding the library; Also, I tried pulling the library .ccp and .h files into the project src folder to see if that would resolve the issue to no avail.
Another thing that I tried was instead of using #include “Adafruit_ADS1X15.h” I tried #include “lib/Adafruit_ADS1X15/src/Adafruit_ADS1X15.h”
When you say the library cannot be found, do you mean:
Error during cloud compile
Error during local compile
Intellisense has a red squiggle under the #include statement and indicates that the header file cannot be found.
If it’s the last one, I’ve seen this happen before, and I never found the root cause. However:
Try quitting and restarting VSCode. This probably won’t help, but it’s worth a try.
Make sure you have a .vscode directory in the top level of your project directory, and it contains settings.json. If you use Particle: Create New Project one is created, but if you created your project manually it will be missing, and the compiler settings may be wrong. There is also a launch.json that will affect the debugger.
If that doesn’t fix it, add the configurations block below to settings.json. You may need to close and reopen the project to get it to update.
What this does is recursively add the directories in the lib directory to the include search path. The crazy thing is that you can then remove it, and it will still work. It seems to trigger something in VSCode that made the problem go away, at least for me.
The correct syntax for #include is just the include file name, no path.