本文介绍了C ++ 17<文件系统>的编译错误;在MinGW上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用新的文件系统库,该库现在是C ++ 17标准的一部分,但是我无法编译。

I want to play around with the new filesystem library that's now apart of the C++17 standard, however I can't get things to compile.

我已经尝试过的事情:


  • 将MinGW更新到8.2.0

  • 使用 g ++ -std = c ++ 17 test.cpp -o test

  • 添加 -lstdc ++ fs 编译(这不起作用,我收到错误 c:/ mingw / bin /../ lib / gcc / mingw32 / 8.2.0 /../../../../ mingw32 / bin / ld.exe:找不到-lstdc ++ fs

  • 使用< filesystem> 以及< experimental\filesystem>

  • Updating MinGW to 8.2.0
  • Compiling with g++ -std=c++17 test.cpp -o test
  • Adding -lstdc++fs to the compilation (this does not work, I get the error c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lstdc++fs)
  • Using <filesystem> as well as <experimental\filesystem>

下面是我的简单测试代码,目的是尝试进行编译:

Here is my simple test code just to try and get things compiling:

#include <iostream>
#include <filesystem>

using namespace std;

int main(int argc, char* argv[]) {
  return 0;
}

并使用 g ++ -std = c ++进行编译17 test.cpp -o test

由此我得到错误:

In file included from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\filesystem:37,
                 from test.cpp:2:
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\fs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\fs_path.h:237:47: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')
    || (__p.has_root_name() && __p.root_name() != root_name()))
                               ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
In file included from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iosfwd:40,
                 from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ios:38,
                 from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ostream:38,
                 from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream:39,
                 from test.cpp:1:

...还有更多错误。 ..

... many more errors ...

c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\fs_path.h:603:7: note: suggested alternative: 'string_view'
       string_type __tmp;
       ^~~~~~~~~~~
       string_view
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\fs_path.h:604:45: error: '__tmp' was not declared in this scope
       if (__str_codecvt_in(__first, __last, __tmp, __cvt))

其他人有什么建议吗?似乎大多数人通过在编译中添加 -lstdc ++ fs 来解决此问题,但就像我说的那样,这对我不起作用。

Does anyone else have any suggestions? It seems like most people are solving this by adding -lstdc++fs to compilation, but like I said that doesn't work for me.

谢谢!

推荐答案

问题在于mingw和gcc / g ++ 8分支本身,而不是带有编译器标志或预处理器指令。该错误已打开。

The issue is with the mingw and gcc/g++ 8 branch itself, not with the compiler flags or pre-processor directives. The bug is open here .

尝试使用带有 #include< experimental / filesystem> mingw-w64-7.x 版本c>指令和 -lstdc ++ fs -std = c ++ 17 标志。这将立即生效,或者等待v9.1.0。

Try using stable mingw-w64-7.x releases with #include <experimental/filesystem> directive and -lstdc++fs -std=c++17 flags. This will work for now, or otherwise wait for v9.1.0.

实验性频道上,您需要使用 std :: experimental :: filesystem 而不是 std :: filesystem

On experimental channel you need to use std::experimental::filesystem instead of std::filesystem.

这篇关于C ++ 17&lt;文件系统&gt;的编译错误;在MinGW上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 01:26