VSCode No such file or directory when running c++ code
This question was a result of confusion between the tasks.json and the c_cpp_properties.json files. I was treating c_cpp_properties.json as though it was used for compilation.
c_cpp_properties.json is used with Intellisense and in no way deals with compilation.
tasks.json is used for compilation. If you're unfamiliar with tasks.json as I was you need to specify the include paths here as well.
In the args section of your tasks.json use "-I" to add an include path, followed by the path you wish to include.
For my problem that command looked like this:
"-I", "C:\Users\Dill\Desktop\temp\header"
Dylan Jackson-LaClair
Updated on February 23, 2021Comments
-
Dylan Jackson-LaClair about 3 years
When I try to run I receive this error:
main.cpp:1:18: fatal error: temp.h: No such file or directory #include "temp.h" compilation terminated.
Intellisense however, detects that this header is present.
Ctrl + left-clicking on #include "temp.h" in main.cpp successfully brings me to the file and the line of code has no squiggly lines underneath it.I have two separate folders for .cpp files and header files and have configured the includePath in c_cpp_properties.json as such:
My workspace folder is temp and the line "${workspaceFolder}/**" should recursively check subfolders for headers. I added the absolute path to the header files with no success.
-
Keavon about 3 yearsNote: this does not work with
**
globs to match recursively. You can also do-IC:\Your\Path
(the-I
flag without a space immediately followed by the path). And you can use variable references like-I${workspaceFolder}
.