# C/C++: fatal error: foo.h: No such file or directory — #include not found

**Code:** `fatal error: No such file or directory` · **Category:** C/C++ · **Seen on:** C/C++, GCC, Clang, CMake

The preprocessor cannot find a header named in `#include`: wrong path, missing include directory (-I), or the library is not installed.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/cpp/header-no-such-file-or-directory)
