为什么我不能在 g++ 4.9.2 中使用 <experimental/filesystem>?

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

我正在尝试使用 filesystem。我的 CMakeLists.txt 中有 -std=c++11 -std=c++1y。 GCC 版本为 4.9.2。但是,我有一个错误:

/home/loom/MyProject/src/main.cpp:5:35: fatal error: experimental/filesystem: No such file or directory
 #include <experimental/filesystem>
                                   ^
compilation terminated.

正确的使用方法是什么std::experimental::filesystem

如果我们查看 libstdc++ status,我们会发现它们确实支持文件系统 TS:

Paper | Title | Status

........

N4100 | File System | Y

但它说:

This page describes the C++14 and library TS support in mainline GCC SVN, not in any particular release.

Wandbox 上的尝试来看,这个库似乎只在最新的开发分支 6.0 上可用,除此之外我找不到更多详细信息。

更新

来自 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.

也相应于 Jonathan Wakely 的 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.

另见 Table 3.1. C++ Command Options