Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

Things I've already tried:

  • 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 <experimentalfilesystem>

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;
}

and compiling with g++ -std=c++17 test.cpp -o test

With this I get the error(s):

In file included from c:mingwlibgccmingw328.2.0includec++filesystem:37,
                 from test.cpp:2:
c:mingwlibgccmingw328.2.0includec++itsfs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
c:mingwlibgccmingw328.2.0includec++itsfs_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:mingwlibgccmingw328.2.0includec++iosfwd:40,
                 from c:mingwlibgccmingw328.2.0includec++ios:38,
                 from c:mingwlibgccmingw328.2.0includec++ostream:38,
                 from c:mingwlibgccmingw328.2.0includec++iostream:39,
                 from test.cpp:1:

... many more errors ...

c:mingwlibgccmingw328.2.0includec++itsfs_path.h:603:7: note: suggested alternative: 'string_view'
       string_type __tmp;
       ^~~~~~~~~~~
       string_view
c:mingwlibgccmingw328.2.0includec++itsfs_path.h:604:45: error: '__tmp' was not declared in this scope
       if (__str_codecvt_in(__first, __last, __tmp, __cvt))

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.

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
668 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

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.

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


If you don't want to go with experimental features, switch to MSYS2. It has v10.2.0-6 of gcc available as of Jan 2021.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...