VSCode Unable to find custom header file directory: fatal error: no such file or directory

The solution is as follows:

First, add the path of the folder where your header file is located in "includepath":[] of C_cpp_properties.json.

Of course, this step is only to tell the vscode header file where it is for debugging, but it is not known when GCC compiles. We know that if you use G + + main.CPP - I library_path - O main can be compiled successfully directly, so we just need to tell vscode to use our own defined commands

There are generally two methods. The first is to add “- I header_file_path” to the args key in tasks.json, as follows:

	"args": [
		"-g",
		"${workspaceFolder}\\src\\*.cpp",
		"-o",
		"${fileDirname}\\src\\${fileBasenameNoExtension}.exe",
		"-I",
		"header_file_path"
	],

But it doesn’t seem to work well in some cases.

The second method is to directly set in setting.json:

  "code-runner.executorMap": {
    "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt -I 'header_file_path' && $dir$fileNameWithoutExt",
  }

Read More: