Hello,
I recently started using this extension so it's possible what I'm trying to do is supported and I've made a mistake somewhere, but I can't find an example with this element.
I have a header file which is from another project that I would like to include in my sketch. I don't want to move it into the workspace directory and would rather just specify the include path. I was able to get the IntelliSense to behave and find the file correctly by modifying the c_cpp_properties.json file, but when I try to build the executable, it errors and says that it can't find the file. Is there a way to specify extra include paths to the compiler as well?
If the h file is in sub-folder, such as /path/to/include/subfolder/xxx.h, you need add /path/to/include/** into includePath instead of /path/to/include.
If you have already done that, but it still doesn't work, try to execute C/Cpp: Reset IntelliSense Database in command palette.
In c_cpp_properties.json, I have as one of the entries in includePath: "/home/ssnover/libraries/RF24/**". In my sketch I include RF24.h and in the directory that's included there is a file RF24.h. I know there's not a small mistake in that part since the IntelliSense is working (I'm able to control-click and it opens the correct file).
I've attempted to execute that command and then executed the Verify command to build and I receive the same error:
[Starting] Verify sketch - nrf-transmitter.ino
Picked up JAVA_TOOL_OPTIONS:
Loading configuration...
Initializing packages...
Preparing boards...
Verifying...
/home/ssnover/develop/home-automation/testing/nrf-transmitter/nrf-transmitter.ino:3:18: fatal error: RF24.h: No such file or directory
#include "RF24.h"
^
compilation terminated.
exit status 1
[Error] Exit with code=1
Is it possible to view the Makefile that's being run or some of the commands being fed to the compiler so I can debug this issue more easily?
Any developments on how to solve this?
There must be an easy way of adding project specific libraries.
Currently there does not appear to be a way to do what you want. The entries in c_cpp_properties.json for includePath tell intellisense where to look. They do NOT tell the compiler. There does not seem to be a makefile (as such) saved where I could find it. However, if you have added an output path entry in .vscode/arduino.json for the protect, go there and look at build.options.json. The interesting entry is otherLibrariesFolders, which points ONLY to the libraries folder of the Arduino IDE specified sketchbook folder. It looks like specifying multiple folders for that entry would do the trick, but there is no way currently to pass that through from the extension configuration settings.
If you are working on a system (OS and file system) that supports symbolic links, here is a work around that should work (not tested). Create a folder (outside of your project) to use as a dummy sketchbook folder, with a nested libraries folder. Create symbolic links in that folder to each of the library folders needed by the project. Change the Arduino IDE sketchbook.path entry ($HOME/.arduino15/preferences.txt on my system) to point at the dummy sketchbook folder. It should not be too difficult to automate backing up, changing, restoring the preferences.txt file. Your project folder could be a child of the created sketchbook folder, making the libraries folder a sibling. Doing it that way, simply pointing the Arduino IDE to that sketchbook folder should let it work directly with your project. As well as the vscode arduino extension.
Wauw, so I have just spent 2 days messing around with includepaths and browse.paths before I stumbled on your post. Thanks for this. I will not search any further for now and keep my includes just in the root folder for now.
IntelliSense is not linked to Arduino's build process. If you want Arduino's builder to find code outside your sketch, you have three choices (best choices first):
Arduino's build interface doesn't allow to set additional search directories except for the path of your current sketch's and Arduino's sketchbook library path.
Maintainers, @dooriya: This issue can be closed as it won't fix. This is a characteristic/limitation of Arduino - every user has to live with or work around it.
Thanks @elektronikworkshop for the information.
You're welcome!
Most helpful comment
Any developments on how to solve this?
There must be an easy way of adding project specific libraries.