19

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 ?

Anatoly
  • 20,799
  • 3
  • 28
  • 42
harold
  • 307
  • 1
  • 2
  • 9

8 Answers8

23

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 in c_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:

  $ touch empty.c
  $ gcc -v -E -dD empty.c

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 Microsoft cl.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 for cl.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.

Scott McPeak
  • 8,803
  • 2
  • 40
  • 79
6

This is due to the extension is missing some includepath when initialize

add the missing lines into your c_cpp_properties.json

"includePath": [
"<arduino ide installation folder>\\tools\\**",
"<arduino ide installation folder>\\hardware\\arduino\\avr\\**",
"<arduino ide installation folder>\\hardware\\tools\\**",
"<arduino ide installation folder>\\hardware\\arduino\\avr\\cores\\arduino"
]

Also add "defines": [ "USBCON" ] under "configurations" to make Serial class work with intellisense

C.H.
  • 191
  • 3
  • 8
1

Try using platformIO extension it makes your life easier. Personally I use VScode with platformIO for my Arduino and ESP32 projects.

Aadhu
  • 11
  • 2
1

I just successfully wasted an hour finding solution to this problem on stack overflow but all in vain and now I have founded the solution which is, if you are using linux, just have to install the g++ compiler from your terminal,

sudo apt install g++

" and you are good to go.

faizal
  • 11
  • 1
1

For those using WSL, it's a common error, resolved by:

  • installing Remote-WSL VS-Code extension
  • setting c_cpp_properties.json includePath to ["${workspaceFolder}/**"] and intelliSenseMode to "linux-clang-x64" (or other intelliSense mode)
  • close VS-Code and open it again from your WSL termnial, you'll see the Status Bar icon as on the screenshot

Now the #include error should be gone

For more information follow the link

Slava.In
  • 597
  • 1
  • 9
  • 22
0

I had the same issue and spent hours trying different solutions, and finally, I realized I had a misspelling in "iostream". It's not an answer to this question, but if you have fallen here with the same error, check spelling as well.

Noora
  • 31
  • 3
0

Cause of the Problem:

My C/C++ Compiler got saved as /use/bin/clang and this was showing the error in my computer.

Operating System: Ubuntu 2022.04

Solutions:

  1. Open Your VSCode and click Settings (at bottom left corner generally).
  2. Now click at Open Settings (JSON) icon (at top right corner) and open the json file.
  3. Add below code in between last part of main {} bracket [If you don't have the bracket then create one].
  "C_Cpp.default.compilerPath": "/usr/bin/gcc",
  "C_Cpp.default.intelliSenseMode": "linux-gcc-x64",

This has solved my problem and I think it will solve the problem for any Linux/Unix OS.

In case, if this doesn't work then try with:

  "C_Cpp.default.compilerPath": "/usr/bin/g++",
  "C_Cpp.default.intelliSenseMode": "linux-gcc-x64",

If you have Windows Operating System then Use the path of your GCC compiler instead of /usr/bin/gcc [this will be something like C:\MinGW\bin].

Shezan
  • 277
  • 2
  • 8
0

In my case this was caused by my includePath being set to {workspaceFolder}/** and not actually having created a workspace yet. Create a project workspace with 'Save Workspace As' and then it should work

Tom Greenwood
  • 1,502
  • 14
  • 17