简体   繁体   中英

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...). 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). Below is the error I am getting

在此处输入图像描述

Have you tried using #include "parser.h" ?

From the C Standard (ISO/IEC 9899:2018 (C18)) , section 6.10.2 " Source file inclusion ":

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.
3. A preprocessing directive of the form
# 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 .

If you want to know where gcc is seeking for source files, I'd suggest you to have a look at this article .

As mikyll98 has detailedly explained and indicated, #include <> and #include “” are for different things. Check which case your parser.h falls into.

In addition to miky's answer, You should also check if the location of your header file is “visible” to 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. You could open VSCode settings, type in the search bar “include path” or “include directories”, and go to the section relevant to 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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