I'm trying to use vscode with arduino but have no success. The problem seems to be something with the libraries path. But I havent been able to fix that ! I'm on linux.
"message": "#include errors detected. Please update your includePath. IntelliSense features for this translation unit (/home/harold/Arduino/Saaf_Curing/Saaf_Curing.ino) will be provided by the Tag Parser.",
I don't know how to find my includePath. I'm not able to do any advices given in vscode.
I wonder if vs code is the right direction at all as it seems complicated ?
Although the question mentions Arduino, the following suggestions apply basically any time VSCode tells you to "update your includePath".
What is includePath?
The
includePath
is an attribute inc_cpp_settings.json
, which is in the.vscode
folder of the main folder you have opened in VSCode using File → Open Folder.You can edit
c_cpp_settings.json
directly, but it is usually easier to use the "C/C++ Configurations GUI". To do that, open the Command Palette (Ctrl+Shift+P) and run "C/C++: Edit Configurations (UI)". Then look for the "Include path" setting.The
includePath
tells VSCode (specifically the IntelliSense component of the C/C++ extension) where to look when resolving#include "filename"
directives. That allows VSCode to see definitions of symbols defined in those files.So should I fiddle with includePath when VSCode tells me to?
Not at first! Before changing the include path, if you haven't already, first set the "Compiler path" to point at your C/C++ compiler, and set "IntelliSense mode" to match the compiler as closely as possible.
You may also need to adjust the Compiler arguments, particularly if the compiler is capable of generating code for multiple targets, for example, both 32-bit and 64-bit code. (If you don't know what that means, skip it at first.)
Next, in Command Palette, run "C/C++: Log Diagnostics". The output will show you which compiler VSCode found and what it detected as its built-in include path and preprocessor defines.
Then, run these commands in a shell:
Here, I have assumed you are using
gcc
as your compiler. If not, substitute the actual compiler command name. If your compiler is not a variant of GCC (for example you are using the Microsoftcl.exe
compiler), you'll need to look at its documentation or Google to find switches that print the predefined macros and include paths (e.g., see here forcl.exe
).Compare the output of the above command to what VSCode shows in its C/C++ diagnostics output. Hopefully they are very similar. If not, try adjusting the Compiler path, IntelliSense mode, or Compiler arguments. Once you've gotten them as close as possible by adjusting just those three settings, go on to the next step.
Now adjust includePath if necessary
If there are still significant differences between the compiler built-in configuration and what VSCode detects, fix that by (in the C/C++ settings UI) modifying the Include path, Defines, and C/C++ standard fields. Re-run the C/C++ Log Diagnostics command to see the effects.
It is probably not necessary to add all of the pre-defined preprocessor symbols. This really only matters if there are
#ifdef
directives that depend on them, and which are causing VSCode to see the wrong code as active. I suggest only adding predefined symbols if, while browsing your code, you see a specific case that VSCode gets wrong.Finally, if your project has header files in places that the compiler does not search by default, that is, you normally have to pass
-I
switches on the compiler command line, add those as well to the Include path. The same goes for any-D
arguments, which must be added to the Defines.This is due to the extension is missing some includepath when initialize
add the missing lines into your c_cpp_properties.json
Also add
"defines": [ "USBCON" ]
under "configurations" to make Serial class work with intellisense