Why can't I use <experimental/filesystem> with g++ 4.9.2?

26,466

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.

Share:
26,466

Related videos on Youtube

Loom
Author by

Loom

Updated on July 10, 2022

Comments

  • Loom
    Loom almost 2 years

    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?

    • Shafik Yaghmour
      Shafik Yaghmour about 9 years
      Look like it currently only work with head
  • Jonathan Wakely
    Jonathan Wakely over 8 years
    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.
  • Shafik Yaghmour
    Shafik Yaghmour over 8 years
    @JonathanWakely this question is a good related question.