211

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.

5
  • 5
    In Mac OS, installing xcode command line tools using xcode-select --install and then restarting vscode solved the problem for me. Commented Dec 12, 2020 at 20:05
  • 3
    For Linux users: Make sure you have g++ installed. Commented May 5, 2021 at 13:38
  • 3
    You are not actually asking a question. How this can be upvoted this high is beyond me.. Commented Jan 28, 2025 at 0:29
  • Everyone can review the system environment variables that include the bin path. Commented Oct 12, 2025 at 13:14
  • @ThiệnHưng what do you mean by this comment? Commented Oct 13, 2025 at 20:25

29 Answers 29

245

Close and re-open Visual Studio Code.

Sign up to request clarification or add additional context in comments.

6 Comments

simple and to the point! Is there any shortcut like invalidate cache and rebuilt indexes?
But why does it work?????????????
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.)
This actually works. But given how well vscode is engineered, it needs to be explained - why?
Dunno about well-engineered, this is Intelli-Sense day0 issue
|
109

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 their 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 Comments

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.
What do I do if the include error is a native library? VS Code is complaining about #include <mono/metadata/assembly.h>
'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?
The problem is, I am not getting the option to add to the include path.
@BugHunterUK is it possible to add/change includePath manually? See this answer for further guidance stackoverflow.com/a/68139743/7769052.
|
95

If you are working with cmake-tools and the error messages say 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.

6 Comments

Before making this change, check if a restart of vscode helps.
not work at all, the include_directories of CMAKE need demos
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.
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).
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).
|
39
  • 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 Comments

After above steps, please restart the vs code.
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.
Simple & Starightforward! Solved my problem! Thanks!
29

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.

3 Comments

Why does this work though?
@Mehdi Charife: It works, because it disables intellisense for all practical purposes, falling back on a dumb tag parser which detects grammar errors only. So, not really a great solution.
@RobinDavies I'm sorry but I forgot why I asked the question. It's been a while.
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 Comments

What if there are no suggestions?
If there is a lightbulb, there are suggestions
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.

Comments

11

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 Comment

If you don't have g++ installed, install it with sudo apt-get install g++
7

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

Comments

3

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
            }
        }
    ]
}

Comments

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"

Comments

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

Comments

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.

Comments

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"

Comments

1

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

apt install build-essential

Comments

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.

Comments

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.

Comments

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"

Comments

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 Comments

#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 Good catch, I was fooled into thinking it was there due to the code block markdown syntax ending in `. Fixed.
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
}

Comments

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.

Comments

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 Comments

@starball The issue I had was that it worked before, without me having to configure anything like this manually, then it suddenly stopped working. My answer just means to serve those that share this experience!
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.

Comments

0

I've solved for me.

You have to be sure install "C/C++ Extension" for VSCode and "Mysys". You can download and check install here

https://code.visualstudio.com/docs/languages/cpp#_example-install-mingwx64-on-windows

and configure your "c_cpp_properties.json" like this.

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/msys64/ucrt64/include",
                "C:/msys64/ucrt64/lib/gcc/x86_64-w64-mingw32/13.1.0"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:/msys64/ucrt64/bin/gcc.exe",
            "intelliSenseMode": "gcc-x64",
            "configurationProvider": "ms-vscode.cpptools"
        }
    ],
    "version": 4
}

The important thing is add below path(s) in includePath

"C:/msys64/ucrt64/include"
"C:/msys64/ucrt64/lib/gcc/x86_64-w64-mingw32/13.1.0"

Comments

0

Apple M2 Pro, Sequoia 15.2

None of the above worked for me. I found the solution on the other IDE support site. The problem was in my broken developer tools.

Step 1.
It can fix the problem.

sudo xcode-select --switch /Library/Developer/CommandLineTools/

Step 2.
If it does not help, try to remove it

sudo rm -rf /Library/Developer/CommandLineTools

and install it again.

xcode-select --install

Comments

0

Errors relating to modern (C++20, C++23, ...) features

At the time of writing, C++20 and C++23 are the most recent standards. Recent compilers support most, if not all of C++20, and a significant number of C++23 features.

However, you may want to check if your default compiler version does support the features you are trying to use.

My guess would be that VS Code uses the default compiler installation to check for syntax errors, and include errors.

For example, in my specific case, I have set the -std=c++23 compiler flag in the VS Code settings.

However, the default compiler on my system is still gcc version 12.2.0. This is not the most up to date version. The reason is this is a Debian system, and the toolchains tend to lag a bit behind the alternatives, for example Ubuntu server systems.

I wanted to use the new std::format and std::println features of C++23.

I get include errors related to the include lines for these headers.

#include <format>
#include <print>

One way to fix this would be to install a more up-to-date compiler.

However, rather than risk breaking your system install, I would suggest considering an alternative solution.

Docker can provide quite a nice solution. It is relatively easy to build a Dockerfile and a Docker container image which contains the latest gcc and g++ compilers.

This will not fix your include errors - you will have to just ignore them - but it is a nice solution to get access to a new compiler without risking breaking other parts of your install.

It is also much easier than installing a second compiler chain. (Which if not done carefully can also break parts of your system.)

I won't give further details here, because it is too much a tangent to the original question.

1 Comment

If you want more information on the Docker solution, create a new question and post a link in the comments here. I will get back to you about it.
0

In my case, the project builds successfully with CMake but VSCode shows errors in the include keyword because it's not able to find the headers.

I was thinking about manually setting the libraries in the includePath inside the .vscode/c_cpp_properties.json but I wanted to avoid thatas it will be pointing to some global cache path from conan.

The solution is that I tried to generate compilation database by adding this to the CMakeLists.txt:

# Generate compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

and updated my .vscode/c_cpp_properties.json to use the generated compile commands:

{
  "configurations": [
    {
      // ...
      "compileCommands": "${workspaceFolder}/path_to_your_build/compile_commands.json"
    }
  ],
}

Comments

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

Comments

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

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.