为什么我不能使用 <experimental/filesystem>使用 g++ 4.9.2? [英] Why can't I use <experimental/filesystem> with g++ 4.9.2?

查看:40
本文介绍了为什么我不能使用 <experimental/filesystem>使用 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++ 命令选项.

这篇关于为什么我不能使用 &lt;experimental/filesystem&gt;使用 g++ 4.9.2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆