Skip to content
Latchkey

gcc/g++ "fatal error: X.h: No such file or directory"

The compiler could not find a header you #included. Either the library’s development package is not installed, or the directory holding the header is not on the include search path.

What this error means

Compilation stops at the #include line with "fatal error: <header>: No such file or directory" and "compilation terminated." It often passes locally where the -dev package is installed.

g++ output
main.cpp:3:10: fatal error: curl/curl.h: No such file or directory
    3 | #include <curl/curl.h>
      |          ^~~~~~~~~~~~~
compilation terminated.

Common causes

Development headers not installed

The runtime library may exist, but the -dev/-devel package that ships the headers (e.g. libcurl4-openssl-dev) is missing on the CI image.

Include directory not on the search path

The header is installed in a custom prefix that the compiler does not search by default, so -I is needed (or the CMake target’s include directories are incomplete).

How to fix it

Install the development package

Add the -dev/-devel package that provides the header.

Terminal
# Debian/Ubuntu
apt-get update && apt-get install -y libcurl4-openssl-dev
# Fedora/RHEL
# dnf install -y libcurl-devel

Add the include directory

For a header in a custom prefix, add it to the compiler’s search path - or to the CMake target.

Terminal
g++ -I/opt/curl/include main.cpp
# CMake equivalent
# target_include_directories(app PRIVATE /opt/curl/include)

How to prevent it

  • Install all -dev/-devel packages your includes require in the runner image.
  • Use find_package()/target_include_directories so include paths are explicit.
  • Prefer pkg-config (pkg-config --cflags) over hard-coded -I paths.

Frequently asked questions

What causes ""fatal error: X.h: No such file""?
The runtime library may exist, but the -dev/-devel package that ships the headers (e.g. libcurl4-openssl-dev) is missing on the CI image.
How do I fix "fatal error: X.h: No such file"?
Add the -dev/-devel package that provides the header.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card