2015-05-07 13 views
23

Tôi đang cố gắng sử dụng filesystem. Tôi có -std=c++11 -std=c++1y trong số CMakeLists.txt. Phiên bản GCC là 4.9.2. Tuy nhiên, tôi đã gặp lỗi:Tại sao tôi không thể sử dụng <thử nghiệm/hệ thống tệp> với g ++ 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. 

Cách nào đúng để sử dụng std::experimental::filesystem?

+0

Có vẻ như nó hiện chỉ hoạt động [với phần đầu] (http://melpon.org/wandbox/permlink/abzPdCEgfwCCct22) –

Trả lời

25

Nếu chúng ta nhìn vào libstdc++ status chúng ta thấy rằng họ làm có hỗ trợ cho hệ thống tập tin TS:

Paper | Title | Status

........

N4100 | File System | Y

nhưng nó nói:

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

và từ cố gắng này trên Wandbox nó trông giống như thư viện này chỉ có trên chi nhánh phát triển mới nhất 6.0 và tôi không thể tìm thấy nhiều chi tiết hơn thế nữa.

Cập nhật

Update từ 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.

Cũng phù hợp để answer here Jonathan Wakely của chúng ta cần phải biên dịch sử dụng -lstdc++fs. Đây được bao phủ trong 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.

Xem thêm Table 3.1. C++ Command Options.

+1

Nó cũng có sẵn trong 'gcc-5-branch' trong Subversion và sẽ được đưa vào bản phát hành GCC 5.3 vào cuối năm nay. –

+1

@JonathanWakely [câu hỏi này] (http://stackoverflow.com/q/33149878/1708801) là một câu hỏi liên quan. –

Các vấn đề liên quan