1 问题
在使用Qt 5.15.2时,使用C++标准库filesystem时,报错如下:
D:\Qt\Qt5.15.2\Tools\mingw810_64\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\bits\fs_path.h:237: error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')
In file included from D:/Qt/Qt5.15.2/Tools/mingw810_64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/filesystem:37,
from ..\app.h:4,
from ..\app.cpp:1:
D:/Qt/Qt5.15.2/Tools/mingw810_64/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&)':
D:/Qt/Qt5.15.2/Tools/mingw810_64/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()))
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
经查是gcc8.1对filesystem支持不好,需要升级编译器版本。
2 解决
参考文档Qt添加构建套件升级编译版本为11.2.0解决问题。
3 总结
C++标准发展的很快,C++11标准刚普及时,后续C++14/C++17/C++20/C++23相继而来,而Qt5默认使用编译器版本是GCC8.1,对C++17不是全面支持,使用filesystem会有编译错误。通过自定义构建套件的方式将编译版本提高到GCC11.2.0,可以完全支持C++17标准。


1756

被折叠的 条评论
为什么被折叠?



