簡體   English   中英

C++17 的編譯錯誤<filesystem>在 MinGW 上

[英]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>以及<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來解決這個問題,但就像我說的那樣,這對我不起作用。

謝謝!

問題在於 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 月,它具有 v10.2.0-6 的gcc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM