0

I have written a very simple c++ program:

#include<filesystem>
using namespace std::filesystem;

int main(){
    return 0;
}

At first, I compiled it with

g++ -c main.cpp -o main.o

and got following errors:

main.cpp:2:22: error: 'filesystem' is not a namespace-name
 using namespace std::filesystem;
                  ^~~~~~~~~~
main.cpp:2:32: error: expected namespace-name before ';' token
 using namespace std::filesystem;
                                ^

I read that I just need to put -std=c++17 in after -c for also compile all the new stuff in c++17.
But when I do so, I get hundreds of errors like:

C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.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:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.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()))

or

C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: At global scope:
C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:511:18: error: specialization of 'std::filesystem::__cxx11::path::__is_encoded_char<wchar_t>' after instantiation
 struct path::__is_encoded_char<wchar_t> : std::true_type  

and many more. Can anybody tell me what I did wrong. The libraries and the compiler are downloaded with the codeBlocks installer, so they should normally be wright.
Thank you in advance!

  • Please put the first few errors in their complete form in the question (they currently look cropped to me). Also, what goes `g++ --version` return? – Ted Lyngmo Jan 24 '21 at 11:09
  • It looks like `g++ --version` will return `8.1.0`. In that case, does [this](https://stackoverflow.com/a/53202056/7582247) help? – Ted Lyngmo Jan 24 '21 at 11:16
  • Perhaps your path is just not properly setup? Can you find `g++` somewhere under `C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0`? Probably `C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/bin/g++` Try compiling with that version and add the options I pointed out in the link. – Ted Lyngmo Jan 24 '21 at 11:41
  • All subdirectories of Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/bin/g++ are finclude, include, include-fixed and install-tools, there is neither a executable nor any file with g++ or gcc as a part of its name – der Gelassene Jan 24 '21 at 11:56
  • g++ --version says: g++ (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. – der Gelassene Jan 24 '21 at 12:10

1 Answers1

1
no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')

this is a bug in mingw 8.1.0. the bug report: https://sourceforge.net/p/mingw-w64/bugs/737

This is fixed in version 9.x, you need to upgrade mingw to a newer version (9.0+)

thakee nathees
  • 877
  • 1
  • 9
  • 16