MinGW 上 C++17 的编译错误<filesystem>
Compilation errors for C++17 <filesystem> on MinGW
我想尝试使用现在与 C++17 标准分开的新filesystem
库,但我无法编译东西。
我已经尝试过的事情:
- 将 MinGW 更新到 8.2.0
- 使用
g++ -std=c++17 test.cpp -o test
编译 - 将
-lstdc++fs
添加到编译中(这不起作用,我收到错误c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lstdc++fs
( - 使用
<filesystem>
和<experimentalfilesystem>
这是我的简单测试代码,只是为了尝试编译:
#include <iostream>
#include <filesystem>
using namespace std;
int main(int argc, char* argv[]) {
return 0;
}
并与g++ -std=c++17 test.cpp -o test
一起编译
有了这个,我得到错误:
In file included from c:mingwlibgccmingw328.2.0includec++filesystem:37,
from test.cpp:2:
c:mingwlibgccmingw328.2.0includec++bitsfs_path.h: In member function 'std::filesystem::__cxx11::path& std::filesystem::__cxx11::path::operator/=(const std::filesystem::__cxx11::path&)':
c:mingwlibgccmingw328.2.0includec++bitsfs_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:mingwlibgccmingw328.2.0includec++iosfwd:40,
from c:mingwlibgccmingw328.2.0includec++ios:38,
from c:mingwlibgccmingw328.2.0includec++ostream:38,
from c:mingwlibgccmingw328.2.0includec++iostream:39,
from test.cpp:1:
。还有更多错误...
c:mingwlibgccmingw328.2.0includec++bitsfs_path.h:603:7: note: suggested alternative: 'string_view'
string_type __tmp;
^~~~~~~~~~~
string_view
c:mingwlibgccmingw328.2.0includec++bitsfs_path.h:604:45: error: '__tmp' was not declared in this scope
if (__str_codecvt_in(__first, __last, __tmp, __cvt))
还有其他人有什么建议吗?似乎大多数人都在通过在编译中添加-lstdc++fs
来解决这个问题,但就像我说的,这对我不起作用。
谢谢!
问题出在 mingw 和 gcc/g++ 8 分支本身,而不是编译器标志或预处理器指令。该错误在此处打开。
尝试使用带有#include <experimental/filesystem>
指令和-lstdc++fs -std=c++17
标志的稳定mingw-w64-7.x
版本。这将暂时有效,否则等待v9.1.0。
experimental
频道上,您需要使用 std::experimental::filesystem
而不是 std::filesystem
.
如果不想使用实验性功能,请切换到 MSYS2。截至 2021 年 1 月,它有 gcc 的 v10.2.0-6 可用。
相关文章:
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- std::filesystem::copy throws filesystem_error
- 如何防止clang格式在流运算符调用之间添加换行符<<
- C++将目录中的所有文件与::filesystem进行比较
- <<操作员在下面的行中工作
- <filesystem> 在 clang 6 和 10 上 #include 错误
- 在带有尾部斜杠的路径上返回 std::filesystem::create_directories() 的值
- std::filesystem 和 std::experimental::filesystem 之间的路径差异
- 如何将 std::filesystem::p ath 转换为 LPCSTR,以便在 LoadLibrary() 变体之一
- 无法使用<filesystem>函数
- 不能将C++的"std::filesystem"库与介子构建一起使用
- Visual Studio 2019 C++ and std::filesystem
- 'std::filesystem::d irectory_iterator' 编译器问题
- std::filesystem::create_directories Visual Studio 2017
- 如何获取 std::filesystem::p ath 中的最后一个目录?
- 为什么目录中的 std::filesystem::file_size 留给实现?
- 标头中有哪些固有的安全漏洞<filesystem>?
- 如何在 C++17 中检索 std::filesystem::file_time_type 的时钟类型