C/C++: fatal error: foo.h: No such file or directory — #include not found
The preprocessor cannot find a header named in #include: wrong path, missing include directory (-I), or the library is not installed.
fatal error: No such file or directoryNo such file or directory #includefatal error: iostream: No such file or directory'stdio.h' file not foundfatal error: Python.h: No such file or directory Meaning
#include "x.h" searches the current file's folder first and then the -I paths; #include <x.h> searches only system and -I paths. Missing development packages (the -dev / -devel ones) and a wrong relative path are the two most common causes.
Common causes
- The library's development package is not installed (libfoo-dev)
- The include directory is not passed with -I (or target_include_directories in CMake)
- Wrong relative path or file name case on Linux
- Generated header not created yet (build order)
- Using <> for a project header or "" for a system one
⚡ Quick fix
- Install the dev package (
sudo apt install libfoo-dev) - Add
-I/path/to/includeortarget_include_directories - Check the exact path and letter case of the file
Detailed fix by platform
Linux
- Find the header:
find / -name "foo.h" 2>/dev/nullanddpkg -S foo.h(Debian/Ubuntu) - Install the package that owns it, e.g.
sudo apt install libssl-dev - See what GCC searches:
echo | g++ -E -Wp,-v -x c++ -
CMake
- Add
target_include_directories(app PRIVATE include)or link the imported target that carries the include path
Code examples
Making the header visible in CMake
add_executable(app src/main.cpp)
target_include_directories(app PRIVATE ${CMAKE_SOURCE_DIR}/include)
# For a system library found with find_package:
find_package(OpenSSL REQUIRED)
target_link_libraries(app PRIVATE OpenSSL::SSL)How to diagnose
- Path — Does the file exist where the compiler looks?
- Flags — Is the directory passed with -I?
- Package — Is the -dev package installed?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in C/C++
- terminate called after throwing an instance of C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check
- double free or corruption C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)
- expected ';' before C/C++: error: expected ';' before 'x' — missing semicolon
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026