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
Question posted in Visual Studio Code
View the official documentation.
View the official documentation.
2
Answers
Have you tried using
#include "parser.h"
?From the C Standard (ISO/IEC 9899:2018 (C18)), section 6.10.2 "Source file inclusion":
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.