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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30103209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 13:42:24  来源:igfitidea点击:

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

c++c++11filesystemsg++libstdc++

提问by Loom

I am trying to use filesystem. I have -std=c++11 -std=c++1yin my CMakeLists.txt. GCC version is 4.9.2. However, I have got an error:

我正在尝试使用filesystem。我-std=c++11 -std=c++1y在我的CMakeLists.txt. 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.

What is the right way to use std::experimental::filesystem?

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

回答by Shafik Yaghmour

If we look at the libstdc++ statuswe see that they do have support for the File System TS:

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

Paper | Title | Status

........

N4100 | File System | Y

纸 | 标题 | 地位

…………

N4100 | 文件系统 | 是

but it says:

但它说:

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

此页面描述了主线 GCC SVN 中的 C++14 和库 TS 支持,而不是任何特定版本。

and from trying this on Wandboxit looks like this library is only available on the latest development branch 6.0and I can not find more details beyond that.

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

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.

它现在也可以在 Subversion 的 gcc-5-branch 中使用,并将包含在今年晚些时候的 GCC 5.3 版本中。

Also accordingly to Jonathan Wakely's answer herewe need to compile using -lstdc++fs. This is covered in the Linking section of gcc documents:

同样根据 Jonathan Wakely 的回答,我们需要使用-lstdc++fs. 这在gcc 文档链接部分中有介绍

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.

GCC 5.3 包括技术规范 ISO/IEC TS 18822:2015 定义的文件系统库的实现。因为这是一个实验性的库扩展,不是 C++ 标准的一部分,它在一个单独的库 libstdc++fs.a 中实现,并且没有共享库。要使用该库,您应该包含并链接 -lstdc++fs。非 POSIX 平台上的库实现不完整,特别是 Windows 支持是基本的。

由于文件系统库的实验性质,关于 ABI 稳定性和向后兼容性的通常保证不适用于它。不能保证任何标头中的组件在不同 GCC 版本之间保持兼容。

Also see Table 3.1. C++ Command Options.

见表 3.1。C++ 命令选项