C++
C++ Header Not Found Fix
The header exists, the include line looks right, and the build stops anyway - because the preprocessor does not search the whole disk for a name: it searches a short, ordered list of directories for a file with exactly that name, character for character, and gives up at the end of the list. This guide separates the five ways that search misses, reads what the diagnostic actually reports, and matches each shape to its repair.
Written November 24, 2026 · Tested with GCC 13.3.0 · 11 min read
- The rule underneath: a header is found by searching an ordered list for an exact name
- How to read the diagnostic
- The first failure: the header name is misspelled
- The second failure: the project header is in a directory the search never visits
Written November 24, 2026
Tested with GCC 13.3.0
What this guide is
Every #include line asks the preprocessor for one file, by name. Before any C++ is compiled, the preprocessor searches for that name, and if the search ends without a match it stops the whole translation with a fatal error: the header name, followed by "No such file or directory". Nothing after the include line is read. The header usually exists - spelled slightly differently, in a directory the search never visits, under different capitalization, or one directory away from where a relative path points. The error is about the search, not about whether the file exists somewhere on the disk.
The five forms in this guide each reproduce the failure with a small, complete program, and the search misses five different ways: a system header's name is misspelled, a project header sits in an include directory that no -I option names, the include line's capitalization differs from the file on disk, angle brackets are used for a header that only the quote form's first search step would find, and a relative path is one directory level off. In each family the failing program is small, the full compiler output is shown, and the fix makes the one search succeed while keeping the rest of the program as it was. Five neighboring shapes in the traps are not this error: a header that is found but empty compiles fine, the include-path option accepts a space form and an equals form, an angle-bracket include succeeds once -I names the directory, and two directories holding the same header name are decided by the order of the -I options.
One neighboring failure is easy to confuse with this one and is not covered here. If the header is found and read, but a type it was supposed to declare is still missing - because the wrong header was included, or the declaration sits below its use - the compiler continues past the include line and fails later, in the code, with errors such as "does not name a type". That failure has its own guide. This guide's error is earlier and blunter: it is reported at the include line itself, it is fatal, and compilation of the file ends there. If the failing line is an #include, this guide is the one that applies.
Build every program in this guide with g++ -std=c++20 -Wall -Wextra. The failing programs are compiled with -c - compile only - because the error stops preprocessing and no program is produced; the fixed programs and the traps are compiled and run, so their output is shown. In the compiler transcripts below, the file names are the names shown on the command line, relative to the directory the command runs in, and multi-file programs list each file under its own name.
The rule underneath: a header is found by searching an ordered list for an exact name
An #include directive searches for a specific header or source file and replaces the directive with that file's entire contents. How the places to search are determined is implementation-defined in the standard; GCC's rules are the concrete ones this guide uses. The lookup order is fixed. For the quote form, #include "file", the directory of the current file is searched first, then any -iquote directories in left-to-right order. For both forms, directories given with -I are then scanned in left-to-right order, followed by -isystem directories, the standard system directories, and finally any -idirafter directories. The angle-bracket form, #include <file>, skips the first two steps: it starts at the -I directories. The skipped step that matters for this guide is the first one - the directory containing the current file - and it is the fourth family below; the only other difference between the forms is the -iquote list, which the angle form likewise skips.
Three consequences of that rule explain every family in this guide. First, the search is by exact name: the preprocessor looks for a file whose name matches the include line character for character, and on a case-sensitive file system capitalization is part of the name - the third family. A misspelling is therefore not a near miss that the search tolerates; it is simply a different name, and no directory holds a file under it - the first family. Second, a directory that is not on the list is not searched at all, however close it sits to the source: a project header in an include subdirectory is invisible until an option names that directory - the second family. Third, a name that contains a path, such as "../config.h", is resolved relative to the starting point of the search - for the quote form, the directory of the file that contains the include line - so the same spelling succeeds or fails depending on how deep that file sits - the fifth family.
The convention that follows from the rule is the one the GCC preprocessor manual states: the angle-bracket form is used for system header files, and the quote form for header files of your own program, because the quote form searches the current file's directory first. The convention is a consequence of the search order, not a separate rule - and the traps show the boundary precisely: an angle-bracket include of a project header works as soon as -I puts its directory on the list both forms share.
So the preprocessor's requirement is threefold at once: a file under the exact spelling used, in a directory the chosen form actually searches, reached before the list runs out. Each family below breaks exactly one part of that, and each fix repairs exactly that part.
How to read the diagnostic
Every failure in the five families prints the same shape of output. The first family's, in full:
fail_misspelled_header.cpp:1:10: fatal error: iostreamm: No such file or directory
1 | #include <iostreamm>
| ^~~~~~~~~~~
compilation terminated.
Read it in order. The first line gives the file and the position - fail_misspelled_header.cpp:1:10 is line 1, column 10, the start of the header name inside the include line - and then the error itself: fatal error, the name that was searched for, and "No such file or directory". The word "fatal" is load-bearing: preprocessing stops here, the rest of the file is never read, and there is no second error hiding behind this one - whatever else might be wrong with the program is not reported until this search succeeds. The next two lines repeat the source line with a caret under the exact name, so the searched spelling can be compared character by character with the file it was meant to name. The last line, compilation terminated., is the same stop stated once more, not a separate problem.
Three practical consequences follow. First, there is exactly one error in each transcript: one include line, one failed search, one fatal error. A real file with several includes can stop at the first missing one, be fixed, and stop again at the next - each stop is this same single error, one name at a time. Second, the name in the error is the first piece of evidence - compare it with the file on disk: spelling, capitalization, and any path prefix are all printed exactly as searched. Third, what the error does not print is the second piece of evidence: the list of directories that were searched. The error says the name was not found, not where it was looked for - which is why the families below are told apart by the layout of the files and the command line, not by differences in the message. All five print the identical sentence; the cause differs.
The first failure: the header name is misspelled
A program whose only include names a header that does not exist - iostreamm, with an extra letter:
#include <iostreamm>
int main() {
return 0;
}
$ g++ -std=c++20 -Wall -Wextra -c -o fail_misspelled_header.o fail_misspelled_header.cpp
fail_misspelled_header.cpp:1:10: fatal error: iostreamm: No such file or directory
1 | #include <iostreamm>
| ^~~~~~~~~~~
compilation terminated.
The search itself worked exactly as designed: every directory on the list was checked, and none of them holds a file named iostreamm. This is the form the error takes when a header name is typed from memory, copied with a typo, or carried over from another language's library, whose header names differ. Note what the diagnostic does not do: unlike some later compile errors, it offers no "did you mean" suggestion - the name is printed, the caret underlines it, and the comparison with the real header's name is left to the reader. The eye slides over an extra letter in a word it has read a hundred times; the caret line is the place to read the name slowly, one character at a time.
The fix corrects the spelling:
#include <iostream>
int main() {
std::cout << "ready" << '\n';
return 0;
}
$ g++ -std=c++20 -Wall -Wextra -o fix_misspelled_header fix_misspelled_header.cpp
$ ./fix_misspelled_header
ready
The output is ready. One letter removed; nothing else in the program was wrong. When the name in the error is a system header and the spelling looks right, check it against the library's documentation rather than memory - several standard headers differ by a single character from a plausible guess, and the search rewards only the exact name.
The second failure: the project header is in a directory the search never visits
A program that includes its own header, config.h - the header file, include/config.h:
#pragma once
inline constexpr int config_value() {
return 42;
}
The main file, fail_missing_include_path.cpp:
#include <iostream>
#include "config.h"
int main() {
std::cout << config_value() << '\n';
return 0;
}
Compiled with no include-path option:
$ g++ -std=c++20 -Wall -Wextra -c -o fail_missing_include_path.o fail_missing_include_path.cpp
fail_missing_include_path.cpp:2:10: fatal error: config.h: No such file or directory
2 | #include "config.h"
| ^~~~~~~~~~
compilation terminated.
The header exists, spelled exactly as the include line spells it - one directory down, in include. The quote form searched the directory containing the main file first, and config.h is not there; it is in include, a directory no option named, so the search never visited it and the remaining steps - the -I list, the system directories - do not hold it either. This is the most common form of the error in real projects: headers are gathered into an include directory, sources into a src directory, and the build command that used to name the directory is lost, simplified, or never written for a new file. The spelling is right and the layout is sensible; the search list is what is incomplete.
The fix adds the directory to the search with -I:
$ g++ -std=c++20 -Wall -Wextra -Iinclude -o fix_missing_include_path fix_missing_include_path.cpp
$ ./fix_missing_include_path
42
The main file is unchanged - the fix's program, fix_missing_include_path.cpp, is the failing program word for word, with the same include/config.h beside it. The output is 42, the value the header's function returns. -Iinclude adds include to the list both include forms search, in left-to-right order among the -I directories and before the standard system directories. The durable habit behind this fix is that the include path is part of the build, stated on the command line or in the build file - a header's location is a fact the compiler has to be told, not one it can infer from the project's layout.
The third failure: the capitalization differs from the file on disk
A program that includes its own header with one capital letter - the header file on disk, config.h:
#pragma once
inline constexpr int config_value() {
return 42;
}
The main file, fail_case_mismatch.cpp:
#include <iostream>
#include "Config.h"
int main() {
std::cout << config_value() << '\n';
return 0;
}
$ g++ -std=c++20 -Wall -Wextra -c -o fail_case_mismatch.o fail_case_mismatch.cpp
fail_case_mismatch.cpp:2:10: fatal error: Config.h: No such file or directory
2 | #include "Config.h"
| ^~~~~~~~~~
compilation terminated.
The header sits in the very directory the quote form searches first, and the search still fails: the name on disk is config.h and the name searched for is Config.h, and on a case-sensitive file system those are two different names, one of which no file bears. This family is the one that survives a move between systems - code written and built on a case-insensitive file system, where the two spellings name the same file, fails the first time it is built on a case-sensitive one, with the include line looking obviously correct to anyone who has seen it work. It also appears after a rename that changed only capitalization, where the file was renamed and the include lines were not, or the other way around.
The fix matches the include line to the file on disk:
#include <iostream>
#include "config.h"
int main() {
std::cout << config_value() << '\n';
return 0;
}
$ g++ -std=c++20 -Wall -Wextra -o fix_case_mismatch fix_case_mismatch.cpp
$ ./fix_case_mismatch
42
The output is 42. One letter's case changed. Either side can be the one to change - rename the file or correct the include - but they must agree exactly, and the include lines are usually the cheaper side: every spelling in every file that includes the header has to match the one name on disk.
The fourth failure: angle brackets skip the directory beside the source
A program that includes its own header with angle brackets - the header file, config.h, in the same directory as the source:
#pragma once
inline constexpr int config_value() {
return 42;
}
The main file, fail_angle_brackets.cpp:
#include <iostream>
#include <config.h>
int main() {
std::cout << config_value() << '\n';
return 0;
}
$ g++ -std=c++20 -Wall -Wextra -c -o fail_angle_brackets.o fail_angle_brackets.cpp
fail_angle_brackets.cpp:2:10: fatal error: config.h: No such file or directory
2 | #include <config.h>
| ^~~~~~~~~~
compilation terminated.
The header is beside the source, spelled exactly right, and the search fails - because the angle-bracket form never looks there. The directory of the current file is the first step of the quote form's search only; the angle form starts at the -I directories and continues through the system directories, none of which hold this project's header. This family appears when an include is written with angle brackets out of habit - every other include in the file uses them, because every other include names a system header - and it is the one family where the delimiters themselves, not the name, the layout, or the command line, are the whole cause. The last trap shows the other side of the same rule: with -I naming the directory, the angle form succeeds, because from the -I step onward the two forms share one list.
The fix switches the delimiters to quotes:
#include <iostream>
#include "config.h"
int main() {
std::cout << config_value() << '\n';
return 0;
}
$ g++ -std=c++20 -Wall -Wextra -o fix_angle_brackets fix_angle_brackets.cpp
$ ./fix_angle_brackets
42
The output is 42. Two characters changed - the brackets became quotes - and the first search step now finds the file where it sits. The durable rule is the manual's convention, now with its reason visible: quotes for a project's own headers, because only the quote form looks beside the source first; angle brackets for system and library headers, whose directories are on the shared part of the list.
The fifth failure: the relative path is one directory off
A program two levels deep that reaches for its header with a relative path - the header file, include/config.h:
#pragma once
inline constexpr int config_value() {
return 42;
}
The main file, src/main.cpp:
#include <iostream>
#include "../config.h"
int main() {
std::cout << config_value() << '\n';
return 0;
}
$ g++ -std=c++20 -Wall -Wextra -c -o fail_wrong_relative_path.o src/main.cpp
src/main.cpp:2:10: fatal error: ../config.h: No such file or directory
2 | #include "../config.h"
| ^~~~~~~~~~~~~
compilation terminated.
A quoted name that contains a path is resolved from the directory of the file that contains the include line: from src, ../config.h names a config.h in the project's top directory - and there is none there; the header is in include, one step to the side. This family appears when a source file is moved deeper or shallower in the tree, when a header is moved into a subdirectory, and when an include line is copied from a file at a different depth, where the same spelling was correct. The error prints the path exactly as written, and the check is mechanical: start at the including file's directory, follow the path by hand, and see which directory it lands in.
The fix corrects the path to where the header actually is:
#include <iostream>
#include "../include/config.h"
int main() {
std::cout << config_value() << '\n';
return 0;
}
$ g++ -std=c++20 -Wall -Wextra -o fix_wrong_relative_path src/main.cpp
$ ./fix_wrong_relative_path
42
The output is 42. The name gained one component, include/, and the path now lands on the file. Where many files include the same header this way, the second family's repair is usually the stronger one - name the directory once with -Iinclude and include the header by its plain name - because a relative path in every source file has to be corrected in every file when the layout changes, while the -I option is corrected in one place.
The fixes in reach order
- The name is misspelled: correct the spelling to the header's real name, read character by character against the documentation or the file on disk.
- The header is in a directory the search never visits: add that directory with
-I- the include line stays as it is. - The capitalization differs: make the include line and the file on disk agree exactly, letter case included.
- Angle brackets name a project header beside the source: switch to quotes, so the current file's directory is searched first - or add the directory with
-Iand keep the brackets. - A relative path lands in the wrong directory: follow it from the including file's directory and correct the components - or replace the path with a plain name plus an
-Ifor its directory. - In every case: the repair makes the search find a file under the exact name used, in a directory the chosen form searches.
Traps
- A header that is found but empty is not this error at all. Here
notes.hexists beside the source and contains nothing:
#include <iostream>
#include "notes.h"
int main() {
std::cout << "ready" << '\n';
return 0;
}
$ g++ -std=c++20 -Wall -Wextra -o probe_empty_header probe_empty_header.cpp
$ ./probe_empty_header
ready
ready. The search asks only whether a file with the name exists in a searched directory; what the file contains is a separate question, answered later, in the code that uses what the header was supposed to declare. A missing-header error therefore always means the file was not found - never that it was found and found wanting - and an include that compiles proves the file's presence, not its contents.
- The -I option accepts its directory as a separate argument. The second family's fix, with the space form instead of the joined form:$ g++ -std=c++20 -Wall -Wextra -I include -o probe_space_form probe_space_form.cpp
$ ./probe_space_form
42
The output is 42, from the same probe_space_form.cpp and the same include/config.h as the second family. -I include and -Iinclude name the same directory and put it in the same place in the search order; the joined form is the common one in build files, but a command line split by a shell or a script into separate words behaves identically.
- The long option takes the directory with an equals sign. The same fix again, through the long alias for -I:
$ g++ -std=c++20 -Wall -Wextra --include-directory=include -o probe_equals_form probe_equals_form.cpp
$ ./probe_equals_form
42
The output is 42. --include-directory is an alias for -I, and its =include form attaches the directory to the option in one word. The equals sign belongs to the long option's syntax; it is not a form of -I itself - in a -I argument, a leading = has a different, sysroot-related meaning in GCC, so the safe equals spelling is the long option's.
- An angle-bracket include succeeds once -I names the directory. The fourth family's header, kept in include and included with brackets:
#include <iostream>
#include <config.h>
int main() {
std::cout << config_value() << '\n';
return 0;
}
$ g++ -std=c++20 -Wall -Wextra -Iinclude -o probe_angle_with_include_path probe_angle_with_include_path.cpp
$ ./probe_angle_with_include_path
42
The output is 42. The two forms differ only in the steps before the -I list: the quote form's extra steps are the current file's directory and the -iquote directories. Once a directory is named with -I, both forms search it, which is why installed libraries - whose directories the build supplies with -I or the system list - are included with angle brackets without trouble, and why the fourth family's fix could equally have been an -I for the source's own directory.
- When two directories hold the same header name, the -I order decides. Here are the two headers - first shadow_a/config.h, which returns 1:
#pragma once
inline constexpr int config_value() {
return 1;
}
Then shadow_b/config.h, which returns 2:
#pragma once
inline constexpr int config_value() {
return 2;
}
And one program includes config.h:
#include <iostream>
#include "config.h"
int main() {
std::cout << config_value() << '\n';
return 0;
}
$ g++ -std=c++20 -Wall -Wextra -Ishadow_a -Ishadow_b -o probe_shadow_order probe_shadow_order.cpp
$ ./probe_shadow_order
1
$ g++ -std=c++20 -Wall -Wextra -Ishadow_b -Ishadow_a -o probe_shadow_order probe_shadow_order.cpp
$ ./probe_shadow_order
2
The outputs are 1 and then 2: the search takes the first directory on the list that holds a matching name and stops, so swapping the two -I options swaps which header the program is built with - no error, no warning, a different program. This is the quiet counterpart of the whole guide: a not-found error at least announces itself, while a found-too-early header changes the build silently. It is also the mechanism behind using -I to override a header deliberately - the manual notes the option can substitute your own version of a header precisely because these directories are searched before the standard ones.
Checklist
- The diagnostic read as a search report: the file and position of the include line, the exact name that was searched for, and "fatal" understood - nothing after the line was read, and this one name is the whole error.
- The searched name compared character by character with the file on disk - spelling and capitalization both, including any path prefix.
- The header's directory confirmed to be one the chosen form searches: beside the source for quotes, or named by
-I,-iquote, or the system list. - The delimiters matching the header's kind: quotes for the project's own headers, angle brackets for system and library headers.
- A relative path followed by hand from the including file's directory to the directory it actually lands in.
- No second directory earlier in the
-Iorder holding a different header under the same name. - The fixed program run, and its output checked against what the program was meant to do.
Related guides on this site
- 'std::unique' Is Not a Member of 'std' Fix
- 'std::search_n' Is Not a Member of 'std' Fix
- 'std::replace' Is Not a Member of 'std' Fix
- 'std::remove' Is Not a Member of 'std' Fix
Sources
- GCC, Directory Options - for
-Iadding a directory to the header search list, for the lookup order (the current file's directory and-iquotefor the quote form first, then-I,-isystem, the standard system directories, and-idirafter, each in left-to-right order), for-Idirectories being searched before the standard system directories, and for--include-directorybeing an alias for-I. - GCC, The C Preprocessor - Header Files - for a header file being requested with the
#includedirective, for system headers declaring the interfaces to parts of the operating system and libraries, and for a program's own headers holding the declarations shared between its source files. - cppreference, Source file inclusion - for the
#includedirective searching for a specific header or source file and replacing the directive with that file's entire contents, for the search's manner being implementation-defined, and for typical implementations searching only the standard include directories for the angle-bracket form while the quote form's search first looks in the directory where the current file resides.
Keep Exploring
Seven tips and seven puzzles so far, each one a short runnable example with the fix explained.
Paste an AddressSanitizer, UBSan, or ThreadSanitizer report and get the bug, the file and line, and the fix \u2014 in plain language.
C++20 and C++23 features, migration paths, and measured trade-offs.
The full C++ hub \u2014 language basics, the standard library, coroutines, and measured comparisons.
Paste a [Service] section and get a plain-language verdict on every sandboxing setting it finds.