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
- Include the specific header and compile with the required standard.
- In CMake set CMAKE_CXX_STANDARD to 17 or 20 as needed.
gcc
#include <filesystem>
g++ -std=c++17 app.cpp -o appHow 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
gcc/clang "no match for 'operator<<'" in CIFix gcc/clang "no match for 'operator<<'" in CI - a type is streamed with << but no suitable overload exists,…
ld "undefined reference to std::filesystem" (needs -lstdc++fs) in CIFix ld "undefined reference to std::filesystem" in CI - older GCC/Clang ship filesystem in a separate library…