Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode No such file or directory when running c++ code [closed]

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.

like image 672
Dylan Jackson-LaClair Avatar asked Dec 29 '18 22:12

Dylan Jackson-LaClair


People also ask

How do I fix VS Code No such file or directory?

You have to compile the . cpp file first(using some cpp compiler like g++) which will give you an object file (like a. out ) that you can run as ./a.

Why does VS Code show no such file or directory?

Basically, the problem is with header files. I think you should try reinstalling mingw, adding it to system path again or try installing the extension in vscode.

Why C file is not running in VS Code?

Go to the menu Code > Preferences > Settings. In the User tab on the left panel, expand the Extensions section. Find and select Run Code Configuration. Find and check the box Run in Terminal.

How do I get C to work on VS Code?

1. We need to click on the extension button that displays a sidebar for downloading and installing the C/C++ extension in the visual studio code. In the sidebar, type C Extension. In this image, click on the Install button to install the C/C++ extension.


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"

like image 73
Dylan Jackson-LaClair Avatar answered Nov 09 '22 05:11

Dylan Jackson-LaClair