#include errors detected in vscode
C++Visual Studio-CodeC++ Problem Overview
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.
C++ Solutions
Solution 1 - C++
Close and re-open Visual Studio Code.
Solution 2 - C++
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.
Solution 3 - C++
If you are working with cmake-tools and the error messages says something is wrong with the configurationProvider, then following actions solved the issue for me:
- Open c_cpp_properties.json. (windows key on windows or cmd key on mac + shift + p, enter "c/c++ edit configurations" and chose 'json'.
- 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:
One other important configuration is the include path. The assumption is that you have this configuration right. May be like following
Solution 4 - C++
- Left mouse click on the bulb of error line
- Click
Edit Include path
- Then this window popup
- Just set
Compiler path
Solution 5 - C++
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.
source: https://code.visualstudio.com/docs/languages/cpp#_intellisense
Solution 6 - C++
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.
Solution 7 - C++
I was trying a hello world program, and this line:
#include <stdio.h>
was underlined green. I tried:
- Deleting the line
- Re-writing the line
- 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
Solution 8 - C++
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++",
Solution 9 - C++
After closing and reopening VS, this should resolve.
Solution 10 - C++
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"
Solution 11 - C++
- For Windows:
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"
Solution 12 - C++
If someone have this problem, maybe you just have to install build-essential.
apt install build-essential
Solution 13 - C++
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.
Solution 14 - C++
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.
Solution 15 - C++
In case you've copied and pasted code into your new file in VS Code
Please delete #include <iostream>
and try to build again.
Solution 16 - C++
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 https://stackoverflow.com/questions/47834825/in-vs-code-disable-error-comments-are-not-permitted-in-json
Solution 17 - C++
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.
Solution 18 - C++
For Windows:
- Please add this directory to your environment variable(Path):
> C:\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin\
- 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.