c++ - 尝试在MSYS2/MinGW-w64上编译时,许多内部标准库会编译错误

标签 c++ compiler-errors std mingw-w64 msys2

我正在尝试在Windows 10的MSYS2/MingGW-w64上静态链接并编译我的项目。但是内部的std库会吐出大量的编译错误,我的意思是很多,超过2k行和200 KB。我怎样才能解决这个问题?
这是第一个错误块:

/mingw64/bin/g++.exe   -I/home/dan9e/cartogrtist/build -I/home/dan9e/cartogrtist/src/block -I/home/dan9e/cartogrtist/src/cliParser -I/home/dan9e/cartogrtist/src/mapArt/mapArtFlat -I/home/dan9e/cartogrtist/src/mapArt/mapArtStaircase -I/home/dan9e/cartogrtist/src/palette -I/home/dan9e/cartogrtist/src/schematic -I/home/dan9e/cartogrtist/src/staircaseColumn -I/mingw64/include/GraphicsMagick -I/home/dan9e/libnbtplusplus/include -I/home/dan9e/libnbtplusplus/include/libnbtplusplus -I/home/dan9e/libnbtplusplus/include/libnbtplusplus/io -I/home/dan9e/libnbtplusplus/include/libnbtplusplus/text -I/mingw64/include/tclap -I/mingw64/include/spdlog -I/mingw64/include/fmt  -g -O2 -O3 -DNDEBUG   -o CMakeFiles/cartogrtist.dir/src/block/block.cpp.obj -c /home/dan9e/cartogrtist/src/block/block.cpp
In file included from C:/msys64/mingw64/include/c++/10.2.0/string:56,
                 from C:/msys64/mingw64/include/c++/10.2.0/bits/locale_classes.h:40,
                 from C:/msys64/mingw64/include/c++/10.2.0/locale:39,
                 from C:/msys64/mingw64/include/fmt/locale.h:11,
                 from C:/msys64/mingw64/include/c++/10.2.0/clocale:42,
                 from C:/msys64/mingw64/include/c++/10.2.0/x86_64-w64-mingw32/bits/c++locale.h:41,
                 from C:/msys64/mingw64/include/c++/10.2.0/bits/localefwd.h:40,
                 from C:/msys64/mingw64/include/c++/10.2.0/ios:41,
                 from C:/msys64/mingw64/include/c++/10.2.0/ostream:38,
                 from C:/msys64/mingw64/include/c++/10.2.0/iostream:39,
                 from C:/msys64/home/dan9e/cartogrtist/src/block/block.h:19,
                 from C:/msys64/home/dan9e/cartogrtist/src/block/block.cpp:17:
C:/msys64/mingw64/include/c++/10.2.0/bits/basic_string.tcc: In function 'std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)':
C:/msys64/mingw64/include/c++/10.2.0/bits/basic_string.tcc:1484:15: error: 'ctype' does not name a type; did you mean '_wctype'?
 1484 |       typedef ctype<_CharT>    __ctype_type;
      |               ^~~~~
      |               _wctype
C:/msys64/mingw64/include/c++/10.2.0/bits/basic_string.tcc:1485:24: error: '__ctype_type' has not been declared
 1485 |       typedef typename __ctype_type::ctype_base         __ctype_base;
      |                        ^~~~~~~~~~~~
C:/msys64/mingw64/include/c++/10.2.0/bits/basic_string.tcc:1501:14: error: '__ctype_type' does not name a type; did you mean '__ctype_base'?
 1501 |        const __ctype_type& __ct = use_facet<__ctype_type>(___in.getloc());
      |              ^~~~~~~~~~~~
      |              __ctype_base
C:/msys64/mingw64/include/c++/10.2.0/bits/basic_string.tcc:1507:12: error: '__ct' was not declared in this scope; did you mean '__c'?
 1507 |        && !__ct.is(__ctype_base::space,
      |            ^~~~
      |            __c
C:/msys64/mingw64/include/c++/10.2.0/bits/basic_string.tcc:1507:20: error: '__ctype_base' is not a class, namespace, or enumeration
 1507 |        && !__ct.is(__ctype_base::space,
      |                    ^~~~~~~~~~~~
其余的可以在下面找到:https://pastebin.com/RaiS6K75
make命令是:
dan9e@RED MINGW64 ~/cartogrtist/build
$ make -j1 1> error.log 2> error.log
为了显示正在运行的命令,在CMake中将CMAKE_VERBOSE_MAKEFILE设置为ON
版本信息:
dan9e@RED MINGW64 ~/cartogrtist/build
$ g++ --version
g++.exe (Rev1, Built by MSYS2 project) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


dan9e@RED MINGW64 ~/cartogrtist/build
$ cmake --version
cmake version 3.17.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).

dan9e@RED MINGW64 ~/cartogrtist/build
$ make --version
GNU Make 4.3
Built for x86_64-pc-msys
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

最佳答案

如果查看包含的文件链:

In file included from C:/msys64/mingw64/include/c++/10.2.0/string:56,
             from C:/msys64/mingw64/include/c++/10.2.0/bits/locale_classes.h:40,
             from C:/msys64/mingw64/include/c++/10.2.0/locale:39,
             from C:/msys64/mingw64/include/fmt/locale.h:11,
             from C:/msys64/mingw64/include/c++/10.2.0/clocale:42,
看到那里有一个/fmt/locale.h。这显然是不正确的,因为标准库头<clocale>不应包含标准库头目录之外的任何内容。
出现此问题的原因是,您已错误地将/mingw64/include/fmt指定为包含路径,因此fmt/locale.h现在可以找到文件#include "locale.h"了,而实际上不应该找到它。
您的构建命令不应包含任何以-I开头的/mingw64开关。默认情况下,在搜索路径上启用了/mingw64/include目录。
要使用位置为/mingw64/include/fmt/format.h的 header ,请在程序中编写#include <fmt/format.h>,因为在/mingw64/include中搜索了该名称,所以可以找到它。

关于c++ - 尝试在MSYS2/MinGW-w64上编译时,许多内部标准库会编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63291350/

相关文章:

c++ - ASIO 聊天 session 类在销毁时抛出异常 : C++ ASIO

compiler-errors - 扫描仪无法解析为9型

c - 无法用 make 编译 | fatal error 设备上没有剩余空间

c - Graphviz 作为库错误 : too many arguments to function ‘agnode’

c++ - int_type 没有命名类型的挫败感

c++ - C++ std::map 中的 "Uninitialised value was created by a stack allocation"

c++ - 为什么我不能通过在 cpp 中返回将 char* 添加到 char*?

C++ 使用预定义参数调用静态函数指针

c++ - MFC中如何实现IExplorerBrowser

c++ - std::string 源中宏的使用