Skip to content
Latchkey

gcc/clang "'X' was not declared" needing <filesystem>/<charconv> in CI

Newer library facilities (std::filesystem, std::optional, std::string_view, std::from_chars) live in their own headers and need a recent -std level. Without both, the names are undeclared.

What this error means

A std:: name from a C++17/20 facility is rejected as not declared, even though the right include seems present, because the standard level is too low.

gcc
app.cpp:6:8: error: 'std::filesystem' has not been declared
    6 |   std::filesystem::path p{"."};
      |        ^~~~~~~~~~

Common causes

How to fix it

Include the header and raise -std

  1. Include the specific header and compile with the required standard.
  2. In CMake set CMAKE_CXX_STANDARD to 17 or 20 as needed.
gcc
#include <filesystem>
g++ -std=c++17 app.cpp -o app

How to prevent it

  • Pin a high enough -std (or CMAKE_CXX_STANDARD) and include the dedicated header for each modern standard-library facility you use.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →