简体   繁体   English

header 文件未找到 VScode 但未给出警告或错误

[英]header file not found VScode but no warnings or errors given

I am trying to run a c program in vsCode but it keeps telling me "no such file or directory" when referring to one of my.h files (yet finds the others just fine...).我正在尝试在 vsCode 中运行一个 c 程序,但它在引用其中一个 my.h 文件时一直告诉我“没有这样的文件或目录”(但发现其他文件还不错......)。 I have tried googling this countless times but all the solutions seem to go way over my head and refer to things I cannot find such as the json file (and googling where that is didnt help either).我已经无数次尝试用谷歌搜索这个问题,但所有解决方案似乎都超出了我的理解范围 go 并且参考了我找不到的东西,例如 json 文件(并且谷歌搜索也没有帮助)。 Below is the error I am getting以下是我收到的错误

在此处输入图像描述

Have you tried using #include "parser.h" ?您是否尝试过使用#include "parser.h"

From the C Standard (ISO/IEC 9899:2018 (C18)) , section 6.10.2 " Source file inclusion ":来自C 标准 (ISO/IEC 9899:2018 (C18)) ,第6.10.2节“源文件包含”:

2 . 2 . A preprocessing directive of the form表单的预处理指令
# include < h-char-sequence > new-line
searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.在一系列实现定义的位置中搜索由 < 和 > 定界符之间的指定序列唯一标识的 header,并导致用 header 的全部内容替换该指令。如何指定位置或标识 header 是实现-定义。
3. A preprocessing directive of the form 3.表单预处理指令
# include " q-char-sequence " new-line
causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read导致用 " 分隔符之间的指定序列标识的源文件的全部内容替换该指令。以实现定义的方式搜索指定的源文件。如果不支持此搜索,或者搜索失败,该指令被重新处理,就好像它读取
# include < h-char-sequence > new-line
with the identical contained sequence (including > characters, if any) from the original directive.具有与原始指令相同的包含序列(包括 > 字符,如果有的话)。

When including a source file, if you use the #include <header.h> notation, the compiler ( gcc in your case) will search the header in a standard list of system directories (and, if used, the directories specified after the -l option), while if you use the #include "header.h" notation, the compiler will search the header in the directory containing the current file .包含源文件时,如果您使用#include <header.h>表示法,编译器(在您的情况下为gcc )将在系统目录的标准列表中搜索 header(如果使用,则在-l之后指定的目录) -l选项),而如果使用#include "header.h"符号,编译器将在包含当前文件的目录中搜索 header 。

If you want to know where gcc is seeking for source files, I'd suggest you to have a look at this article .如果你想知道gcc在哪里寻找源文件,我建议你看看这篇文章

As mikyll98 has detailedly explained and indicated, #include <> and #include “” are for different things.正如 mikyll98 已详细解释和指出的那样, #include <>#include “”用于不同的事物。 Check which case your parser.h falls into.检查您的 parser.h 属于哪种情况。

In addition to miky's answer, You should also check if the location of your header file is “visible” to VScode.除了 miky 的回答之外,您还应该检查 header 文件的位置是否对 VScode“可见”。 This is where the json file comes in. VSCode settings is sometimes funky (I think) because sometimes you have to resort to json config files to fully modify the settings, and the location / configurable knobs of such json files are not explicit.这就是 json 文件的用武之地。VSCode 设置有时很奇怪(我认为),因为有时您必须求助于 json 配置文件才能完全修改设置,而此类 json 文件的位置/可配置旋钮并不明确。 You could open VSCode settings, type in the search bar “include path” or “include directories”, and go to the section relevant to C/C++.您可以打开 VSCode 设置,在搜索栏中输入“include path”或“include directories”,然后输入 go 到与 C/C++ 相关的部分。 There should be an option where you either add extra directories via the GUI, or let VSCode open a json file and you can add your path to that file.应该有一个选项,您可以通过 GUI 添加额外的目录,或者让 VSCode 打开一个 json 文件,然后您可以将路径添加到该文件。 But be aware that the configurable knobs of said json file isn't explicit and you'll have to look up VSCode's documentation website to know what specific json attribute to add.但请注意,上述 json 文件的可配置旋钮并不明确,您必须查找 VSCode 的文档网站才能知道要添加哪些特定的 json 属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM