196

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.

2
  • 1
    In Mac OS, installing xcode command line tools using xcode-select --install and then restarting vscode solved the problem for me.
    – zdm
    Commented Dec 12, 2020 at 20:05
  • 1
    For Linux users: Make sure you have g++ installed. Commented May 5, 2021 at 13:38

25 Answers 25

199

Close and re-open Visual Studio Code.

6
  • 3
    simple and to the point! Is there any shortcut like invalidate cache and rebuilt indexes?
    – Mrityunjai
    Commented Aug 7, 2021 at 22:46
  • 12
    But why does it work????????????? Commented Jan 5, 2023 at 13:43
  • 2
    It will also show an error if there is an include error in the included file itself. =) (This is why I am here. An hour wasted.)
    – SergeyR
    Commented May 16, 2023 at 15:09
  • This actually works. But given how well vscode is engineered, it needs to be explained - why? Commented Sep 22, 2023 at 3:40
  • Dunno about well-engineered, this is Intelli-Sense day0 issue Commented Jun 29 at 7:06
99

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

8
  • 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 and another answer of mine. Commented Aug 31, 2019 at 23:09
  • 1
    What do I do if the include error is a native library? VS Code is complaining about #include <mono/metadata/assembly.h> Commented Jan 7, 2020 at 19:03
  • 8
    '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? Commented Sep 16, 2020 at 23:56
  • 2
    The problem is, I am not getting the option to add to the include path. Commented Jan 28, 2022 at 18:37
  • 2
    @BugHunterUK is it possible to add/change includePath manually? See this answer for further guidance stackoverflow.com/a/68139743/7769052.
    – banan3'14
    Commented Jan 30, 2022 at 17:05
90

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.
5
  • 2
    Before making this change, check if a restart of vscode helps. Commented May 30, 2022 at 19:34
  • not work at all, the include_directories of CMAKE need demos
    – xgqfrms
    Commented Jan 18, 2023 at 5:58
  • I tried all answers below but nothing helped. I was working on a file called C.cpp that is imported into B.cpp and was then imported into main.cpp. Opening main.cpp in the editor fixed all issues.
    – nreh
    Commented May 29, 2023 at 19:16
  • Finally, a solution. Adding include_directories in CMakeLists.txt worked for me. I hope it doesn't mess up with my otherwise "modern" CMake code (targets, etc).
    – alfC
    Commented Nov 15, 2023 at 19:38
  • this is bad advice. if you are already using CMake, you should make your life easier by using CMake Tools, and you should use target_include_directories (rather than include_directories).
    – starball
    Commented Apr 1 at 23:57
37
  • 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
3
  • 1
    After above steps, please restart the vs code.
    – akash
    Commented Oct 3, 2021 at 12:03
  • 6
    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. Commented Oct 16, 2021 at 17:41
  • Simple & Starightforward! Solved my problem! Thanks! Commented May 27, 2022 at 6:03
25

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.

1
  • Why does this work though? Commented Sep 19, 2023 at 19:46
18

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

2
  • 21
    What if there are no suggestions? Commented Jan 7, 2020 at 19:19
  • 1
    If there is a lightbulb, there are suggestions
    – SHINIGAMI
    Commented Aug 20, 2021 at 5:56
11

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.

0
10

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++",
1
  • 1
    If you don't have g++ installed, install it with sudo apt-get install g++ Commented Mar 7, 2021 at 19:11
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

0
2

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"
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

2

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.

2

Faced this issue with Mac M1 chip and was unable to compile and run a .cpp file which had #include <bits/stdc++.h> header.

Upon investigation I got to know that the <bits/stdc++.h> header is not part of the C++ standard; rather, it's a header file specific to the GNU Compiler Collection (GCC). Apple Clang, being a different compiler, may not include this header by default.

  • So, specific to your project configurations, you can set the compilerPath to point at the path where you have installed the GNU g++ compiler.
  • To find out if you have ever installed GNU gcc compiler with homebrew before, use the command brew info gcc. This will give out the version of the compiler if it exists with homebrew list.
  • Use the command which g++-{your-specific-version} eg. which g++-13, in my case this gave the output of /opt/homebrew/bin/g++-13 which I then used to set the compilerPath in C/C++ Configuration file as well as the tasks.json file attached below.
//for c++17 build
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "compile",
            "type": "shell",
            "command": "/opt/homebrew/bin/g++-13",
            "args": [
                "-std=c++17",
                "-o",
                "${fileBasenameNoExtension}",
                "${file}"
            ],
            "group": {
                "kind": "build",
                "isDefault": false
            }
        },
        {
            "label": "compile and run",
            "type": "shell",
            "command": "/opt/homebrew/bin/g++-13 -std=c++17 -o ${fileBasenameNoExtension} ${file} && ./${fileBasenameNoExtension} < input.txt > output.txt",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
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"

1

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

apt install build-essential
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.

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.

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.

2
  • 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
    Commented Mar 17, 2022 at 7: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
    Commented Mar 17, 2022 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
}
0

On MacOS (Macbook Pro M1), nothing of the above worked. I had only .hpp and .tpp file of the template class in my project, but creating main.cpp solved the issue.

0

I am using CMake Tools and this issue arose out of nowhere, I'm not exactly sure what I did that caused it, but I solved it in the following way:

I opened .vscode/c_cpp_properties.json, which somehow existed in my workspace even though I never created nor needed it, and added a configurationProvider key to my configuration with a value of ms-vscode.cmake-tools:

            "configurationProvider": "ms-vscode.cmake-tools"

All my include errors went away. It was clear to me that it was a CMake Tools issue within VS Code because compiling worked just fine and only those included files were affected that I either generated with CMake into my build directory (protobuf files) or that had to be included externally (with find_package).

If you don't have this file in your workspace, you can create it by clicking Edit "includePath" setting when you hover over the error squiggles and click Quick Fix.... It will be created for you.

Hope it helps anyone!

2
0

I had the same problem with including the path for the Eigen library. The following steps solved it:

  1. Find the path for the package which VSCode is not able to detect. For example, let's say my Eigen folder is installed in /opt/homebrew/Celler/eigen/3.4.0_1/include/eigen3/Eigen.
  2. open Command Palette.
  3. type C/C++:Edit Configurations (JSON).
  4. under "configurations": section, inside "includePath":, add the above folder address as another element in the list. It should now look likethis

Now save the file and restart VSCode.

-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.

-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.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.