154

I am using Visual Studio Code in my C++ project. I installed Microsoft C/C++ Extension for VS Code. I got the following error:

#include errors detected. Please update your includePath. IntelliSense features for this translation unit (/path/to/project/file.cpp) will be provided by the Tag Parser.

banan3'14
  • 3,810
  • 3
  • 24
  • 47
  • 5
    generally self-answered questions are ok, but then you should write a clear question and an anwer that is more than just a link to an external resource. – jps Aug 09 '17 at 07:49
  • 1
    In Mac OS, installing xcode command line tools using `xcode-select --install` and then restarting vscode solved the problem for me. – zdm Dec 12 '20 at 20:05
  • 1
    For Linux users: Make sure you have `g++` installed. – Farbod Ahmadian May 05 '21 at 13:38

22 Answers22

167

Close and re-open Visual Studio Code.

Ivy Growing
  • 2,688
  • 2
  • 17
  • 23
88

The answer is here: How to use C/Cpp extension and add includepath to configurations.

Click the light bulb and then edit the JSON file which is opened. Choose the right block corresponding to your platform (there are Mac, Linux, Win32 – ms-vscode.cpptools version: 3). Update paths in includePath (matters if you compile with VS Code) or browse.paths (matters if you navigate with VS Code) or both.

Thanks to @Francesco Borzì, I will append his answer here:

You have to Left click on the bulb next to the squiggled code line.

If a #include file or one of its dependencies cannot be found, you can also click on the red squiggles under the include statements to view suggestions for how to update your configuration.

enter image description here

banan3'14
  • 3,810
  • 3
  • 24
  • 47
  • 1
    Regarding `includePath` and `browse.path`: your explanation is not quite right. *Both* are used while browsing, neither is used during compilation. See the [VSCode FAQ](https://code.visualstudio.com/docs/cpp/faq-cpp#_what-is-the-difference-between-includepath-and-browsepath) and another [answer](https://stackoverflow.com/a/57734835/2659307) of mine. – Scott McPeak Aug 31 '19 at 23:09
  • 1
    What do I do if the include error is a native library? VS Code is complaining about `#include ` – Aaron Franke Jan 07 '20 at 19:03
  • 4
    'Add to "includePath"' is not an option on my editor, which does have the C/C++ extension. Could I get some insight as to why? – Ethan Groat Sep 16 '20 at 23:56
  • @EthanGroat, perhaps you have disabled error squiggles? Could you check options `C_Cpp.errorSquiggles` and `C_Cpp.default.enableConfigurationSquiggles` in settings? – banan3'14 Oct 22 '20 at 20:43
  • 2
    The problem is, I am not getting the option to add to the include path. – BugHunterUK Jan 28 '22 at 18:37
  • 2
    @BugHunterUK is it possible to add/change `includePath` manually? See this answer for further guidance https://stackoverflow.com/a/68139743/7769052. – banan3'14 Jan 30 '22 at 17:05
  • This is the correct solution!!!!! – HAO LEE Jun 30 '22 at 03:00
  • How update paths in includePath ? – Dmitriy Ogureckiy Jul 11 '22 at 16:17
83

If you are working with cmake-tools and the error messages says something is wrong with the configurationProvider, then you have 2 options:

  1. Use ms-vscode.cpptools instead of ms-vscode.cmake-tools
  2. Define the headers in CMakeLists.txt

Option 1: Use ms-vscode.cpptools instead of ms-vscode.cmake-tools.

  1. Open c_cpp_properties.json. (windows key on windows or cmd key on mac + shift + p, enter "c/c++ edit configurations" and chose 'json'.
  2. Enter ms-vscode.cpptools as value for configurationProvider instead of ms-vscode.cmake-tools or whatever you have.

How it should look like after the replacement of configurationProvider:

enter image description here

One other important configuration is the include path. The assumption is that you have this configuration right. May be like following

enter image description here

Option 2: Define the headers in CMakeLists.txt

When configurationProvider is set to ms-vscode.cmake-tools in c_cpp_properties.json, VS Code uses the include information defined in the CMakeLists.txt instead of reading the includePath configs in VS Code.

So you need to setup the include path correctly:

  1. using the include_directories command (rather than the target_include_directories command) to define the headers
  2. Configure the project to reflect the change happened in the previous step.
mckelvin
  • 3,918
  • 1
  • 29
  • 22
Alessandro Giusa
  • 1,660
  • 15
  • 11
31
  • Left mouse click on the bulb of error line
  • Click Edit Include path
  • Then this window popup

enter image description here

  • Just set Compiler path
akash
  • 727
  • 5
  • 13
  • 1
    After above steps, please restart the vs code. – akash Oct 03 '21 at 12:03
  • 4
    I have this set to `/usr/bin/g++`, IntelliSense mode set to linux-gcc-x64, and the include path set to include `${workspaceFolder}/**` and I still get include path errors. I do have GCC and G++ installed. I have the same problem with Clang. – Aaron Franke Oct 16 '21 at 17:41
  • Simple & Starightforward! Solved my problem! Thanks! – Hassan Risvy May 27 '22 at 06:03
17

I ended up here after struggling for a while, but actually what I was missing was just:

If a #include file or one of its dependencies cannot be found, you can also click on the red squiggles under the include statements to view suggestions for how to update your configuration.

enter image description here

source: https://code.visualstudio.com/docs/languages/cpp#_intellisense

Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
13

I'm on a Macbook M1 Pro, and I had red squiggly error lines all over my C++ files. To solve, I did this:

  1. Open Preferences -> Settings
  2. Search for intelliSenseEngine
  3. Change "C_Cpp: Intelli Sense Engine" from Default to Tag Parser

alternatively, you could create a .vscode folder in your project root, and then create a settings.json with the content of

{
    "C_Cpp.intelliSenseEngine" : "Tag Parser"
}

ideally, you should have a c_cpp_properties.json file in the same folder with the right settings as well.

Note: I got this idea from Github here.

Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
Blundering Philosopher
  • 6,245
  • 2
  • 43
  • 59
10

The error message "Please update your includePath" does not necessarily mean there is actually a problem with the includePath. The problem may be that VSCode is using the wrong compiler or wrong IntelliSense mode. I have written instructions in this answer on how to troubleshoot and align your VSCode C++ configuration with your compiler and project.

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

I was trying a hello world program, and this line:

#include <stdio.h>

was underlined green. I tried:

  1. Deleting the line
  2. Re-writing the line
  3. Clicking the yellow bulb and choosing to update

fixed the error warning. i don't know if it fixed the actual problem. But then i'm compiling via a linux VM on Windows 10

Zach Smith
  • 8,458
  • 13
  • 59
  • 133
5

Go to your c_cpp_properties.json file by searching from settings.There you might see the following code

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu17",
            "cppStandard": "c++17",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

Change the compiler path as below

"compilerPath": "/usr/bin/g++",
Sihat Afnan
  • 742
  • 7
  • 14
2

An alternative answer would be opening VS Code in remote WSL, if you going to compile files with g++. Just close your VS Code and open WSL and type code . After that the File Explorer shows that VS Code is now running in the context of WSL with the title bar [WSL: Ubuntu]. But make sure you'd installed the GNU compiler tools and the GDB debugger on WSL.

source: https://code.visualstudio.com/docs/cpp/config-wsl

Thor1n
  • 43
  • 4
1

After closing and reopening VS, this should resolve.

Patrick
  • 119
  • 1
  • 3
1

1.Install Mingw-w64

2.Then Edit environment variables for your account "C:\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin"

3.Reload

  • For MAC

    1.Open search ,command + shift +P, and run this code “c/c++ edit configurations (ui)”

    2.open file c_cpp_properties.json and update the includePath from "${workspaceFolder}/**" to "${workspaceFolder}/inc"

remonsam
  • 19
  • 2
1

If someone have this problem, maybe you just have to install build-essential.

apt install build-essential
Picki
  • 469
  • 4
  • 11
1

For me, using Ubuntu, I just had to install gcc to solve this issue.

sudo apt install gcc

Then, set the compiler path to gcc. Go to your c_cpp_properties.json file, set:

"compilerPath": "/usr/bin/gcc"
Emmanuel Murairi
  • 321
  • 2
  • 15
1

after you install the c/c++ extension, two files are created inside .vscode folder.

open c_cpp_properties.json file and paste this key-value pair inside configuration object.(if it doesn't already exists)

"configurationProvider": "ms-vscode-cpptools"

if it does already exists in the object, see if the value part is ms-vscode-cmaketools. if such it is, replace that existing line with above line.

this will allow you to execute your cpp files along with c files.

navinrangar
  • 904
  • 10
  • 20
1

I solved the error on my Mac by just clicking on the Edit "include path settings" and changing the compiler path to /usr/bin/clang.

banan3'14
  • 3,810
  • 3
  • 24
  • 47
0

In my case I did not need to close the whole VS-Code, closing the opened file (and sometimes even saving it) solved the issue.

Mohammed Noureldin
  • 14,913
  • 17
  • 70
  • 99
0

I had luck removing the comments from c_cpp_properties.json in the .vscode folder. Comments aren't permitted in json files by default and you can't simply rename it .jsonc. Referenced In VS Code, disable error "Comments are not permitted in JSON"

0

My header file was in include/head.h, code in src/code.cpp. I wrote

#include "head.h"

and got this error. Changing it to

#include "../include/head.h"

fixed it.

Alex Li
  • 246
  • 4
  • 11
  • 1
    `#include '../include/head.h` shouldn't even compile. It should result in an error `missing terminating ' character`. Did you mean `#include "../include/head.h"`? – banan3'14 Mar 17 '22 at 07:47
  • @banan3'14 Good catch, I was fooled into thinking it was there due to the code block markdown syntax ending in `. Fixed. – Alex Li Mar 17 '22 at 20:05
0

I solved this problem, once I removed configurationProvider node and set cStandard and cppStandard to default values:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}",
                "${workspaceFolder}/**",
                "${workspaceFolder}/test",
                "/opt/qt5/include/QtCore",
                "${workspaceFolder}/test"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "${default}",
            "cppStandard": "${default}",
            "intelliSenseMode": "linux-clang-x64"
        }
    ],
    "version": 4
}
Olga Pshenichnikova
  • 1,509
  • 4
  • 22
  • 47
-1

For Windows:

  1. Please add this directory to your environment variable(Path):

C:\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\

  1. For Include errors detected, mention the path of your include folder into

"includePath": [ "C:/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/include/" ]

, as this is the path from where the compiler fetches the library to be included in your program.

Sohail Aslam
  • 727
  • 4
  • 24
-1

In case you've copied and pasted code into your new file in VS Code

Please delete #include <iostream> and try to build again.

banan3'14
  • 3,810
  • 3
  • 24
  • 47
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30557105) – Ailurophile Dec 12 '21 at 03:46