【发布时间】:2019-07-04 06:25:58
【问题描述】:
我想使用新的 filesystem 库,它现在是 C++17 标准的一部分,但是我无法编译。
我已经尝试过的事情:
- 将 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>以及<experimental\filesystem>
这是我的简单测试代码,只是为了尝试编译:
#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:\mingw\lib\gcc\mingw32\8.2.0\include\c++\filesystem:37,
from test.cpp:2:
c:\mingw\lib\gcc\mingw32\8.2.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:\mingw\lib\gcc\mingw32\8.2.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:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iosfwd:40,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ios:38,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ostream:38,
from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream:39,
from test.cpp:1:
...更多错误...
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\fs_path.h:603:7: note: suggested alternative: 'string_view'
string_type __tmp;
^~~~~~~~~~~
string_view
c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\fs_path.h:604:45: error: '__tmp' was not declared in this scope
if (__str_codecvt_in(__first, __last, __tmp, __cvt))
还有其他人有什么建议吗?似乎大多数人都通过在编译中添加 -lstdc++fs 来解决这个问题,但就像我说的那样,这对我不起作用。
谢谢!
【问题讨论】:
-
我认为你需要在编译命令中添加
-lstdc++fs -
OP 说他已经尝试过了,@Galik。
-
我很确定
<filesystem>现在不能与 MinGW 一起使用...... -
您能否提供您使用的推荐包括
-lstdc++fs?库标志的位置很重要 -
@Fureeish 我开始怀疑这一点。我以为他们的文件说确实如此,但我一定是错的。你知道我应该改用什么吗?
标签: c++ filesystems c++17