VSCode No such file or directory when running c++ code

Viewed 42091

When I try to run my code 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: c_cpp_properties screenshot

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.

1 Answers

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"

Related