Compile error when std::filesystem header file is

2020-03-26 05:44发布

问题:

I am trying to compile a simple C++ program with std::filesytem header file included!

#include <iostream>
#include <filesystem>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

On compiling I get the following error

In file included from C:/PROGRA~1/MINGW-~1/X86_64~2.0-W/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from C:\Users\{User}\CLionProjects\untitled3\main.cpp:2:
C:/PROGRA~1/MINGW-~1/X86_64~2.0-W/mingw64/lib/gcc/x86_64-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:/PROGRA~1/MINGW-~1/X86_64~2.0-W/mingw64/lib/gcc/x86_64-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()))
                               ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~

I am on windows OS using MingW 8.1.0 and Clion as the IDE and as depicted on this https://en.cppreference.com/w/cpp/compiler_support seems like GCC 8.1 already supports std:fileystem

ToolChain config

EDIT: Language level is set in my CMakeList as shown below

set(CMAKE_CXX_STANDARD 17)

回答1:

I am on windows OS using MingW 8.1.0 and Clion as the IDE

I only implemented the MinGW support for std::filesystem recently and it's not present in GCC 8. It's currently only available in the GCC subversion trunk.

and as depicted on this https://en.cppreference.com/w/cpp/compiler_support seems like GCC 8.1 already supports std:fileystem

Only for non-Windows platforms. The Windows support is very different to the POSIX support and took a lot of extra work.