der Gelassene
der Gelassene

Reputation: 3

Cannot compile c++ program including filesystem

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!

Upvotes: 0

Views: 973

Answers (1)

thakee nathees
thakee nathees

Reputation: 945

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+)

Upvotes: 1

Related Questions