fatal error: filesystem: No such file or directory

C++C++17

C++ Problem Overview


Using, CentOs 7.1, gcc version 6.1.0 (GCC) I receive this error:

fatal error: filesystem: No such file or directory

on this line

#include <filesystem>

compiling with

g++ main.cpp -o main -std=c++17

where is the problem?

C++ Solutions


Solution 1 - C++

It seems you have to include <filesystem> like this:

#include <experimental/filesystem>

Don't forget to add -lstdc++fs as a GCC flag!

Here is the proof: Coliru

If that doesn't work, then that probably means that you don't have filesystem in your configuration.

Also, as @MartinR. pointed out, the experimental is no longer needed in GCC 8+.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobertAaltoView Question on Stackoverflow
Solution 1 - C++Arnav BorborahView Answer on Stackoverflow