繁体   English   中英

无法编译 c++ 包含文件系统的程序

[英]Cannot compile c++ program including filesystem

我写了一个非常简单的 c++ 程序:

#include<filesystem>
using namespace std::filesystem;

int main(){
    return 0;
}

起初,我用

g++ -c main.cpp -o main.o

并出现以下错误:

main.cpp:2:22: error: 'filesystem' is not a namespace-name
 using namespace std::filesystem;
                  ^~~~~~~~~~
main.cpp:2:32: error: expected namespace-name before ';' token
 using namespace std::filesystem;
                                ^

我读到我只需要将 -std=c++17 放在 -c 之后即可编译 c++17 中的所有新内容。
但是当我这样做时,我会收到数百个错误,例如:

C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-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&)':
C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-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()))

要么

C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: At global scope:
C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:511:18: error: specialization of 'std::filesystem::__cxx11::path::__is_encoded_char<wchar_t>' after instantiation
 struct path::__is_encoded_char<wchar_t> : std::true_type  

还有很多。 谁能告诉我我做错了什么。 库和编译器与 codeBlocks 安装程序一起下载,因此它们通常应该是正确的。
先感谢您!

no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')

这是 mingw 8.1.0 中的错误。 错误报告: https://sourceforge.net/p/mingw-w64/bugs/737

这在 9.x 版本中已修复,您需要将 mingw 升级到更新版本 (9.0+)

我写了一个非常简单的 c++ 程序:

#include<filesystem>
using namespace std::filesystem;

int main(){
    return 0;
}

起初,我用

g++ -c main.cpp -o main.o

并得到以下错误:

main.cpp:2:22: error: 'filesystem' is not a namespace-name
 using namespace std::filesystem;
                  ^~~~~~~~~~
main.cpp:2:32: error: expected namespace-name before ';' token
 using namespace std::filesystem;
                                ^

我读到我只需要在 -c 之后放入 -std=c++17 即可编译 c++17 中的所有新内容。
但是当我这样做时,我会收到数百个错误,例如:

C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-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&)':
C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-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()))

或者

C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h: At global scope:
C:/Program Files/CodeBlocks/MinGW/lib/gcc/i686-w64-mingw32/8.1.0/include/c++/bits/fs_path.h:511:18: error: specialization of 'std::filesystem::__cxx11::path::__is_encoded_char<wchar_t>' after instantiation
 struct path::__is_encoded_char<wchar_t> : std::true_type  

还有很多。 谁能告诉我我做错了什么。 库和编译器是使用 codeBlocks 安装程序下载的,因此它们通常应该是正确的。
先感谢您!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM