Kafka
Kafka

Reputation: 820

how can I use std::filesystem with mingw32-make and msys2 on windows

I'm trying to compile my linux code on windows. It blocks because of my use of std::filesystem. So I try to do a minimal example according to this post :

C++17 filesystem using nuwen MinGW on Windows 10

I use the same code :

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
    std::cout << "Current path is " << fs::current_path() << '\n';
}

I use msys2. Ok, when I do g++ -std=c++17 ../main.cpp , it works well :

Current path is "C:\Users\Guillaume\Documents\dev\C++\test\filesystem\build"

But my project is definitevely too big to be use only with g++. So I use cmake and mingw32-make. But, it doesn't work and I have the same error than in the upper post. Complementary information :

g++ --version
g++.exe (Rev2, Built by MSYS2 project) 9.2.0
Copyright (C) 2019 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.

and

mingw32-make.exe --version
GNU Make 4.2.1
Built for x86_64-w64-mingw32
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

My question : what should I do to be able to compile my code with mingw32-make under msys2 ?

edit : the start of the error (too big for stackoverflow)

 mingw32-make.exe
[ 50%] Building CXX object CMakeFiles/filesystem.dir/main.cpp.obj
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp:2:
C:/ProgramData/chocolatey/lib/mingw/tools/install/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:/ProgramData/chocolatey/lib/mingw/tools/install/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()))
                               ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iosfwd:40,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:38,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
                 from C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp:1:
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/postypes.h:221:5: note: candidate: 'template<class _StateT> bool std::operator!=(const std::fpos<_StateT>&, const std::fpos<_StateT>&)'
     operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs)
     ^~~~~~~~
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/postypes.h:221:5: note:   template argument deduction/substitution failed:
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp:2:
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:60: note:   'std::filesystem::__cxx11::path' is not derived from 'const std::fpos<_StateT>'
    || (__p.has_root_name() && __p.root_name() != root_name()))
                                                            ^
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_algobase.h:64,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/char_traits.h:39,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:40,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
                 from C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp:1:
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_pair.h:456:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
     operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
     ^~~~~~~~
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_pair.h:456:5: note:   template argument deduction/substitution failed:
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp:2:
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:60: note:   'std::filesystem::__cxx11::path' is not derived from 'const std::pair<_T1, _T2>'
    || (__p.has_root_name() && __p.root_name() != root_name()))
                                                            ^
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_algobase.h:67,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/char_traits.h:39,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:40,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
                 from C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp:1:
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_iterator.h:311:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)'
     operator!=(const reverse_iterator<_Iterator>& __x,
     ^~~~~~~~
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_iterator.h:311:5: note:   template argument deduction/substitution failed:
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp:2:
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:60: note:   'std::filesystem::__cxx11::path' is not derived from 'const std::reverse_iterator<_Iterator>'
    || (__p.has_root_name() && __p.root_name() != root_name()))
                                                            ^
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_algobase.h:67,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/char_traits.h:39,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:40,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
                 from C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp:1:
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_iterator.h:349:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)'
     operator!=(const reverse_iterator<_IteratorL>& __x,
     ^~~~~~~~
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_iterator.h:349:5: note:   template argument deduction/substitution failed:
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp:2:
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:237:60: note:   'std::filesystem::__cxx11::path' is not derived from 'const std::reverse_iterator<_Iterator>'
    || (__p.has_root_name() && __p.root_name() != root_name()))
                                                            ^
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_algobase.h:67,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/char_traits.h:39,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ios:40,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/ostream:38,
                 from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/iostream:39,
                 from C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp:1:
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/stl_iterator.h:1124:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)'
     operator!=(const move_iterator<_IteratorL>& __x,

...

 C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:180:7: note:   template argument deduction/substitution failed:
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:174:5: note: candidate: 'std::filesystem::__cxx11::path::path(std::filesystem::__cxx11::path::string_type&&, std::filesystem::__cxx11::path::format)'
     path(string_type&& __source, format = auto_format)
     ^~~~
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:174:5: note:   no known conversion for argument 1 from 'std::basic_string_view<wchar_t>' to 'std::filesystem::__cxx11::path::string_type&&' {aka 'std::__cxx11::basic_string<wchar_t>&&'}
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:167:5: note: candidate: 'std::filesystem::__cxx11::path::path(std::filesystem::__cxx11::path&&)'
     path(path&& __p) noexcept
     ^~~~
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:167:5: note:   no known conversion for argument 1 from 'std::basic_string_view<wchar_t>' to 'std::filesystem::__cxx11::path&&'
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:165:5: note: candidate: 'std::filesystem::__cxx11::path::path(const std::filesystem::__cxx11::path&)'
     path(const path& __p) = default;
     ^~~~
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:165:5: note:   no known conversion for argument 1 from 'std::basic_string_view<wchar_t>' to 'const std::filesystem::__cxx11::path&'
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:163:5: note: candidate: 'std::filesystem::__cxx11::path::path()'
     path() noexcept { }
     ^~~~
C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:163:5: note:   candidate expects 0 arguments, 1 provided
mingw32-make[2]: *** [CMakeFiles\filesystem.dir\build.make:62: CMakeFiles/filesystem.dir/main.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:75: CMakeFiles/filesystem.dir/all] Error 2
mingw32-make: *** [Makefile:83: all] Error 2

and the CMakeLists.txt :

cmake_minimum_required(VERSION 2.8.9)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

project (filesystem)
add_executable(filesystem main.cpp)
target_link_libraries(filesystem stdc++fs )

edit 2 :

I have modified my environnement path, and put C:\tools\msys64 on the top.

I use cmake-gui, the log of the configure is :

The C compiler identification is GNU 8.1.0
The CXX compiler identification is GNU 8.1.0
Check for working C compiler: C:/ProgramData/chocolatey/bin/gcc.exe
Check for working C compiler: C:/ProgramData/chocolatey/bin/gcc.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/ProgramData/chocolatey/bin/g++.exe
Check for working CXX compiler: C:/ProgramData/chocolatey/bin/g++.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
Configuring done

the log from set(CMAKE_VERBOSE_MAKEFILE ON) :

mingw32-make.exe
"C:\Program Files\CMake\bin\cmake.exe" -SC:\Users\Guillaume\Documents\dev\C++\test\filesystem -BC:\Users\Guillaume\Documents\dev\C++\test\filesystem\build --check-build-system CMakeFiles\Makefile.cmake 0
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Guillaume/Documents/dev/C++/test/filesystem/build
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\Guillaume\Documents\dev\C++\test\filesystem\build\CMakeFiles C:\Users\Guillaume\Documents\dev\C++\test\filesystem\build\CMakeFiles\progress.marks
C:/tools/msys64/mingw64/bin/mingw32-make -f CMakeFiles\Makefile2 all
mingw32-make[1]: Entering directory 'C:/Users/Guillaume/Documents/dev/C++/test/filesystem/build'
C:/tools/msys64/mingw64/bin/mingw32-make -f CMakeFiles\filesystem.dir\build.make CMakeFiles/filesystem.dir/depend
mingw32-make[2]: Entering directory 'C:/Users/Guillaume/Documents/dev/C++/test/filesystem/build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\Guillaume\Documents\dev\C++\test\filesystem C:\Users\Guillaume\Documents\dev\C++\test\filesystem C:\Users\Guillaume\Documents\dev\C++\test\filesystem\build C:\Users\Guillaume\Documents\dev\C++\test\filesystem\build C:\Users\Guillaume\Documents\dev\C++\test\filesystem\build\CMakeFiles\filesystem.dir\DependInfo.cmake --color=
Scanning dependencies of target filesystem
mingw32-make[2]: Leaving directory 'C:/Users/Guillaume/Documents/dev/C++/test/filesystem/build'
C:/tools/msys64/mingw64/bin/mingw32-make -f CMakeFiles\filesystem.dir\build.make CMakeFiles/filesystem.dir/build
mingw32-make[2]: Entering directory 'C:/Users/Guillaume/Documents/dev/C++/test/filesystem/build'
[ 50%] Building CXX object CMakeFiles/filesystem.dir/main.cpp.obj
C:\ProgramData\chocolatey\bin\g++.exe    -std=c++17 -o CMakeFiles\filesystem.dir\main.cpp.obj -c C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp
In file included from C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
                 from C:\Users\Guillaume\Documents\dev\C++\test\filesystem\main.cpp:2:
C:/ProgramData/chocolatey/lib/mingw/tools/install/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:/ProgramData/chocolatey/lib/mingw/tools/install/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()))

...
...

My CMAKE_CXX_COMPILER is still C:/ProgramData/chocolatey/bin/g++.exe. It's probably the problem ... but what can I do ?

Upvotes: 0

Views: 2541

Answers (1)

Kafka
Kafka

Reputation: 820

The problem comes from the version of gcc used by cmake. In order to use the correct version, I change the order of my environnement path (system->advanced systems parameters->environment variable->path) and put "C:\tools\msys64\mingw64\bin" on the top. Finally, I suppressed from my system environment the paths which can overload the path of msys2 gcc.

Hope it can help someone else.

Upvotes: 3

Related Questions