linux 检测到vscode“#include错误,请更新您的includePath

g52tjvyc  于 2022-12-11  发布在  Linux
关注(0)|答案(7)|浏览(1181)

我试着在arduino上使用vscode,但是没有成功。问题似乎出在库的路径上。但是我还没有能够修复它!我在linux上。
“消息”:“检测到#个include错误.请更新您得includePath.此翻译公寓(/home/harold/Arduino/Saaf_Curing/Saaf_Curing.ino)得智能感知功能将由标记分析器提供.",
我不知道如何找到我的includePath。我无法执行vscode中给出的任何建议。
我想知道VS代码是否是正确的方向,因为它看起来很复杂?

eagi6jfj

eagi6jfj1#

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

What is includePath?

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

So should I fiddle with includePath when VSCode tells me to?

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.

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.)
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.
Then, run these commands in a shell:

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

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

Now adjust includePath if necessary

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

hkmswyz6

hkmswyz62#

这是由于扩展在初始化时缺少一些includepath
将缺少的行添加到c_cpp_properties.json中

"includePath": [
"<arduino ide installation folder>\\tools\\**",
"<arduino ide installation folder>\\hardware\\arduino\\avr\\**",
"<arduino ide installation folder>\\hardware\\tools\\**",
"<arduino ide installation folder>\\hardware\\arduino\\avr\\cores\\arduino"
]

同时在“配置”下添加"defines": [ "USBCON" ],以使串行类与intellisense一起工作

bhmjp9jg

bhmjp9jg3#

尝试使用platformIO扩展,它会让你的生活变得更容易。就我个人而言,我在Arduino和ESP32项目中使用带有platformIO的VScode。

enyaitl3

enyaitl34#

我刚刚成功地浪费了一个小时找到解决这个问题的堆栈溢出,但都是徒劳的,现在我已经找到了解决方案,这是,如果你正在使用linux,只需安装g编译器从您的终端,
sudo apt安装g

“你可以走了。

0wi1tuuw

0wi1tuuw5#

对于使用WSL的用户,这是一个常见错误,可通过以下方法解决:

  • 安装Remote-WSL VS代码扩展
  • c_cpp_properties.jsonincludePath设置为["${workspaceFolder}/**"],将intelliSenseMode设置为"linux-clang-x64"(或其他智能感知模式)
  • 关闭VS-Code并从WSL终端再次打开它,您将看到状态栏图标,如screenshot上所示

现在,#include错误应该消失了
有关更多信息,请访问the link

kjthegm6

kjthegm66#

我也遇到了同样的问题,花了几个小时尝试不同的解决方案,最后,我意识到我在“iostream”中有一个拼写错误。这不是这个问题的答案,但如果你在这里遇到了同样的错误,也要检查拼写。

3phpmpom

3phpmpom7#

问题原因:

我的C/C++编译器被保存为/use/bin/clang,这在我的计算机中显示了错误。

  • 操作系统:Ubuntu 2022.04版 *
    解决方案:

1.打开您的VSCode并单击设置(通常位于左下角)。
1.现在点击打开设置(JSON)图标(在右上角)并打开json文件。
1.在主{}括号 * 的最后一部分之间添加以下代码[如果没有括号,则创建一个]*。

"C_Cpp.default.compilerPath": "/usr/bin/gcc",
  "C_Cpp.default.intelliSenseMode": "linux-gcc-x64",

这已经解决了我的问题,我认为它将解决任何Linux/Unix操作系统的问题。
如果这不起作用,请尝试:

"C_Cpp.default.compilerPath": "/usr/bin/g++",
  "C_Cpp.default.intelliSenseMode": "linux-gcc-x64",

如果您使用Windows操作系统,则使用愚者编译器的路径而不是/usr/bin/gcc [类似于C:\MinGW\bin]。

相关问题