vscode "#include 检测到错误.请更新您的包含路径 [英] vscode "#include errors detected. Please update your includePath

查看:129
本文介绍了vscode "#include 检测到错误.请更新您的包含路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 vscode 与 arduino 一起使用,但没有成功.问题似乎与库路径有关.但我一直无法解决这个问题!我在 linux 上.

I'm trying to use vscode with arduino but have no success. The problem seems to be something with the libraries path. But I havent been able to fix that ! I'm on linux.

message":检测到#include 错误".请更新您的包含路径.此翻译单元 (/home/harold/Arduino/Saaf_Curing/Saaf_Curing.ino) 的 IntelliSense 功能将由标签解析器提供.",

"message": "#include errors detected. Please update your includePath. IntelliSense features for this translation unit (/home/harold/Arduino/Saaf_Curing/Saaf_Curing.ino) will be provided by the Tag Parser.",

我不知道如何找到我的 includePath.我无法执行 vscode 中给出的任何建议.

I don't know how to find my includePath. I'm not able to do any advices given in vscode.

我想知道 vs 代码是否是正确的方向,因为它看起来很复杂?

I wonder if vs code is the right direction at all as it seems complicated ?

推荐答案

虽然问题提到了 Arduino,但以下建议基本上适用于 VSCode 告诉您更新您的 includePath"的任何时候.

Although the question mentions Arduino, the following suggestions apply basically any time VSCode tells you to "update your includePath".

includePathc_cpp_settings.json中的一个属性,在你在VSCode中打开的主文件夹的.vscode文件夹中使用文件 → 打开文件夹.

The includePath is an attribute in c_cpp_settings.json, which is in the .vscode folder of the main folder you have opened in VSCode using File → Open Folder.

您可以直接编辑 c_cpp_settings.json,但通常使用C/C++ 配置 GUI"更容易.为此,请打开命令面板 (Ctrl+Shift+P) 并运行C/C++:编辑配置 (UI)".然后查找包含路径"设置.

You can edit c_cpp_settings.json directly, but it is usually easier to use the "C/C++ Configurations GUI". To do that, open the Command Palette (Ctrl+Shift+P) and run "C/C++: Edit Configurations (UI)". Then look for the "Include path" setting.

includePath 告诉 VSCode(特别是 C/C++ 扩展) 在解析 #include "filename" 指令时查找的位置.这允许 VSCode 查看这些文件中定义的符号的定义.

The includePath tells VSCode (specifically the IntelliSense component of the C/C++ extension) where to look when resolving #include "filename" directives. That allows VSCode to see definitions of symbols defined in those files.

一开始不是!在更改包含路径之前,如果您还没有设置,请先将编译器路径"设置为指向您的 C/C++ 编译器,并将智能感知模式"设置为尽可能与编译器匹配.

Not at first! Before changing the include path, if you haven't already, first set the "Compiler path" to point at your C/C++ compiler, and set "IntelliSense mode" to match the compiler as closely as possible.

您可能还需要调整编译器参数,特别是如果编译器能够为多个目标生成代码,例如 32 位和 64 位代码.(如果你不知道那是什么意思,先跳过它.)

You may also need to adjust the Compiler arguments, particularly if the compiler is capable of generating code for multiple targets, for example, both 32-bit and 64-bit code. (If you don't know what that means, skip it at first.)

接下来,在命令面板中,运行C/C++:日志诊断".输出将显示 VSCode 找到了哪个编译器,以及它检测到的内置包含路径和预处理器定义的内容.

Next, in Command Palette, run "C/C++: Log Diagnostics". The output will show you which compiler VSCode found and what it detected as its built-in include path and preprocessor defines.

然后,在 shell 中运行这些命令:

Then, run these commands in a shell:

  $ touch empty.c
  $ gcc -v -E -dD empty.c

这里,我假设您使用 gcc 作为编译器.如果不是,请替换实际的编译器命令名称.如果您的编译器不是 GCC 的变体(例如您使用的是 Microsoft cl.exe 编译器),您需要查看其文档或 Google 以查找打印预定义宏和包含路径的开关(例如,请参阅 此处 用于 cl.exe.

Here, I have assumed you are using gcc as your compiler. If not, substitute the actual compiler command name. If your compiler is not a variant of GCC (for example you are using the Microsoft cl.exe compiler), you'll need to look at its documentation or Google to find switches that print the predefined macros and include paths (e.g., see here for cl.exe).

将上述命令的输出与 VSCode 在其 C/C++ 诊断输出中显示的内容进行比较.希望它们非常相似.如果没有,请尝试调整编译器路径、智能感知模式或编译器参数.通过仅调整这三个设置使它们尽可能接近后,继续下一步.

Compare the output of the above command to what VSCode shows in its C/C++ diagnostics output. Hopefully they are very similar. If not, try adjusting the Compiler path, IntelliSense mode, or Compiler arguments. Once you've gotten them as close as possible by adjusting just those three settings, go on to the next step.

如果编译器内置配置与 VSCode 检测到的内容之间仍然存在显着差异,请通过(在 C/C++ 设置 UI 中)修改包含路径、定义和 C/C++ 标准字段来解决该问题.重新运行 C/C++ 日志诊断命令查看效果.

If there are still significant differences between the compiler built-in configuration and what VSCode detects, fix that by (in the C/C++ settings UI) modifying the Include path, Defines, and C/C++ standard fields. Re-run the C/C++ Log Diagnostics command to see the effects.

可能没有必要添加所有预定义的预处理器符号.这真的只有在有 #ifdef 指令时才重要依赖于它们,并且导致 VSCode 将错误的代码视为活动的.如果在浏览代码时发现 VSCode 出错的特定情况,我建议仅添加预定义符号.

It is probably not necessary to add all of the pre-defined preprocessor symbols. This really only matters if there are #ifdef directives that depend on them, and which are causing VSCode to see the wrong code as active. I suggest only adding predefined symbols if, while browsing your code, you see a specific case that VSCode gets wrong.

最后,如果你的项目在编译器默认不搜索的地方有头文件,也就是你通常要通过-I 在编译器命令行上切换,将它们也添加到包含路径中.对于任何 -D 参数,必须添加到定义中.

Finally, if your project has header files in places that the compiler does not search by default, that is, you normally have to pass -I switches on the compiler command line, add those as well to the Include path. The same goes for any -D arguments, which must be added to the Defines.

这篇关于vscode "#include 检测到错误.请更新您的包含路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆