Why can#39;t I use lt;experimental/filesystemgt; with g++ 4.9.2?(为什么我不能使用 lt;experimental/filesystemgt;使用 g++ 4.9.2?)
问题描述
我正在尝试使用 文件系统.我的 CMakeLists.txt 中有 -std=c++11 -std=c++1y.GCC 版本是 4.9.2.但是,我遇到了一个错误:
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.
std::experimental::filesystem的正确使用方法是什么?
What is the right way to use std::experimental::filesystem?
推荐答案
如果我们看一下 libstdc++ 状态 我们看到它们确实支持文件系统 TS:
If we look at the libstdc++ status we see that they do have support for the File System TS:
纸 |标题 |状态
........
N4100 |文件系统 |是的
N4100 | File System | Y
但它说:
本页面描述了主线 GCC SVN 中的 C++14 和库 TS 支持,而不是任何特定版本.
This page describes the C++14 and library TS support in mainline GCC SVN, not in any particular release.
从 Wandbox 上尝试这个库,看起来这个库仅在最新开发中可用分支 6.0,除此之外我找不到更多细节.
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.
更新
来自 Jonathan Wakely 的更新:
Update from Jonathan Wakely:
它现在也可以在 Subversion 的 gcc-5-branch 中使用,并将在今年晚些时候包含在 GCC 5.3 版本中.
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 的 此处回答,我们需要使用 -lstdc++fs.这在 gcc 的 Linking 部分中有介绍文件:
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 包含由技术规范 ISO/IEC TS 18822:2015 定义的文件系统库的实现.因为这是一个实验性的库扩展,而不是 C++ 标准的一部分,所以它在一个单独的库 libstdc++fs.a 中实现,并且没有共享库.要使用该库,您应该包含并链接 -lstdc++fs.库实现在非 POSIX 平台上是不完整的,特别是 Windows 支持是基本的.
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.
由于文件系统库的实验性质,通常对 ABI 稳定性和向后兼容性的保证不适用于它.无法保证任何标头中的组件在不同的 GCC 版本之间保持兼容.
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.
另请参见 表 3.1.C++ 命令选项.
这篇关于为什么我不能使用 <experimental/filesystem>使用 g++ 4.9.2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么我不能使用 <experimental/filesystem&
基础教程推荐
- 这个宏可以转换成函数吗? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 常量变量在标题中不起作用 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
