C++ #include 在 vscode 中检测到的错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45583473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
#include errors detected in vscode
提问by banan3'14
I am using Visual Studio Code in my C++ project. I installed Microsoft C/C++ Extension for VS Code. I got the following error:
我在我的 C++ 项目中使用 Visual Studio Code。我为 VS Code安装了Microsoft C/C++ Extension。我收到以下错误:
#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.
#include 检测到错误。请更新您的包含路径。此翻译单元 (
/path/to/project/file.cpp
) 的IntelliSense 功能将由标签解析器提供。
采纳答案by banan3'14
The answer is here: How to use C/Cpp extension and add includepath to configurations.
答案在这里:如何使用 C/Cpp 扩展并将包含路径添加到配置中。
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.
单击灯泡,然后编辑打开的 JSON 文件。选择与您的平台对应的正确块(有Mac
, Linux
, Win32
– ms-vscode.cpptools 版本:3)。更新路径includePath
(如果您使用 VS Code 编译很重要)或browse.paths
(如果您使用 VS Code 导航很重要)或两者兼而有之。
Thanks to @Francesco Borzì, I will append his answer here:
感谢@Francesco Borzì,我将在此处附上他的回答:
You can also click Right mouse button on the underlined code.
您也可以Right 在带下划线的代码上单击鼠标按钮。
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.
如果
#include
找不到文件或其依赖项之一,您还可以单击包含语句下的红色波浪线以查看有关如何更新配置的建议。
回答by Ivy Growing
Tried these solutions and many others over 1 hour. Ended up with closing VS Code and opening it again. That's simple.
在 1 小时内尝试了这些解决方案和许多其他解决方案。最终关闭 VS Code 并再次打开它。这很简单。
回答by Francesco Borzi
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.
如果找不到 #include 文件或其依赖项之一,您还可以单击 include 语句下的红色波浪线以查看有关如何更新配置的建议。
source: https://code.visualstudio.com/docs/languages/cpp#_intellisense
来源:https: //code.visualstudio.com/docs/languages/cpp#_intellisense
回答by Zach Smith
I was trying a hello world program, and this line:
我正在尝试一个 hello world 程序,这一行:
#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
修复了错误警告。我不知道它是否解决了实际问题。但后来我通过 Windows 10 上的 linux VM 进行编译
回答by Scott McPeak
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 answeron how to troubleshoot and align your VSCode C++ configuration with your compiler and project.
错误消息“请更新您的 includePath”并不一定意味着includePath
. 问题可能是 VSCode 使用了错误的编译器或错误的 IntelliSense 模式。我在这个答案中写了关于如何排除故障并使你的 VSCode C++ 配置与你的编译器和项目保持一致的说明。
回答by remonsam
- For Windows:
- 对于Windows:
1.Install Mingw-w64
1.安装 Mingw-w64
2.Then Edit environment variablesfor your account "C:\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin"
2.然后为您的帐户编辑环境变量“C:\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin”
3.Reload
3.重新加载
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"
对于MAC
1.打开搜索,command + shift +P,运行这段代码“c/c++编辑配置(ui)”
2. 打开文件 c_cpp_properties.json 并将 includePath 从 "${workspaceFolder}/**" 更新为 "${workspaceFolder}/inc"
回答by Hridaya Nagaria
For Windows:
对于 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\
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/" ]
"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.
,因为这是编译器从中获取要包含在程序中的库的路径。
回答by Picki
If someone have this problem, maybe you just have to install build-essential.
如果有人遇到这个问题,也许你只需要安装 build-essential。
apt install build-essential
回答by Patrick
After closing and reopening VS, this should resolve.
关闭并重新打开 VS 后,这应该可以解决。