Sam*_*McC 9 c++ filesystems c++17
我想使用filesystem现在属于 C++17 标准的新库,但是我无法编译。
我已经尝试过的事情:
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;
}
Run Code Online (Sandbox Code Playgroud)
并编译 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:
Run Code Online (Sandbox Code Playgroud)
...更多错误...
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))
Run Code Online (Sandbox Code Playgroud)
还有其他人有什么建议吗?似乎大多数人都通过添加-lstdc++fs到编译来解决这个问题,但就像我说的那样对我不起作用。
谢谢!