fatal error: No such file or directory C/C++ Origin: Application & API OSI layer 7 · Application Last updated 15 Oct 2026

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.

Exact message you may see 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
Seen on: C/C++ GCC Clang CMake

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

  1. Install the dev package (sudo apt install libfoo-dev)
  2. Add -I/path/to/include or target_include_directories
  3. Check the exact path and letter case of the file

Detailed fix by platform

Linux

  1. Find the header: find / -name "foo.h" 2>/dev/null and dpkg -S foo.h (Debian/Ubuntu)
  2. Install the package that owns it, e.g. sudo apt install libssl-dev
  3. See what GCC searches: echo | g++ -E -Wp,-v -x c++ -

CMake

  1. 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

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

  1. Path — Does the file exist where the compiler looks?
  2. Flags — Is the directory passed with -I?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

C compiler cannot create executables — configure: error: C compiler cannot create executables / no acceptable C compiler found in $PATH (C/C++)C compiler cannot cre…C1083 — MSVC: fatal error C1083: Cannot open include file: 'foo.h': No such file or directory (C/C++)C1083command not found — bash: command not found (Linux)command not foundCould not find a package configuration file — CMake Error: Could not find a package configuration file provided by "Foo" (requested version 1.2) (C/C++)Could not find a pack…does not appear to contain CMakeLists.txt — CMake Error: The source directory does not appear to contain CMakeLists.txt (C/C++)does not appear to co…Killed signal terminated program cc1plus — g++: fatal error: Killed signal terminated program cc1plus — compilation terminated (out of memory) (C/C++)Killed signal termina…missing separator — Make: Makefile:5: *** missing separator. Stop. (spaces instead of a tab) (C/C++)missing separatorNo rule to make target — Make: *** No rule to make target 'foo.c', needed by 'foo.o'. Stop. (C/C++)No rule to make targetfatal err…

Explore the map of this error Full error map →

🧠 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.