I am trying to use filesystem. I have -std=c++11 -std=c++1y
in my CMakeLists.txt
. GCC version is 4.9.2
. However, I have got an error:
/home/loom/MyProject/src/main.cpp:5:35: fatal error: experimental/filesystem: No such file or directory
#include <experimental/filesystem>
^
compilation terminated.
What is the right way to use std::experimental::filesystem
?
If we look at the libstdc++ status we see that they do have support for the File System TS:
Paper | Title | Status
........
N4100 | File System | Y
but it says:
This page describes the C++14 and library TS support in mainline GCC SVN, not in any particular release.
and from trying this on Wandbox it looks like this library is only available on the latest development branch 6.0
and I can not find more details beyond that.
Update
Update from Jonathan Wakely:
It's also now available in the gcc-5-branch in Subversion, and will be included in the GCC 5.3 release later this year.
Also accordingly to Jonathan Wakely's answer here we need to compile using -lstdc++fs
. This is covered in the Linking section of gcc documents:
GCC 5.3 includes an implementation of the Filesystem library defined by the technical specification ISO/IEC TS 18822:2015. Because this is an experimental library extension, not part of the C++ standard, it is implemented in a separate library, libstdc++fs.a, and there is no shared library for it. To use the library you should include and link with -lstdc++fs. The library implementation is incomplete on non-POSIX platforms, specifically Windows support is rudimentary.
Due to the experimental nature of the Filesystem library the usual guarantees about ABI stability and backwards compatibility do not apply to it. There is no guarantee that the components in any header will remain compatible between different GCC releases.
Also see Table 3.1. C++ Command Options.