fatal error: No such file or directory C/C++ Origin: Application & API 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):

command 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…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 targetnot a member of std — C++: error: 'optional' in namespace 'std' does not name a template type — wrong -std standard (C/C++)not a member of stdredefinition of — C++: error: redefinition of 'class X' / multiple definition — missing include guard (C/C++)redefinition ofundefined reference to — C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status (C/C++)undefined reference toundefined reference to main — C/C++: undefined reference to `main' — (.text+0x20) in crt1.o (C/C++)undefined reference t…fatal 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.