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

1

25

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?

Rarebit answered 7/5, 2015 at 13:54 Comment(1)
Look like it currently only work with headCarn
C
26

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.

Carn answered 7/5, 2015 at 14:27 Comment(2)
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.Harveyharvie
@JonathanWakely this question is a good related question.Carn

© 2022 - 2024 — McMap. All rights reserved.