尝试在 MSYS2/MinGW-w64 上编译时出现许多内部标准库编译错误

Many internal std library compile errors when trying to compile on MSYS2/MinGW-w64

我正在尝试静态 link 并在 Windows 10 上 MSYS2/MingGW-w64 上编译我的项目。但是内部标准库会吐出大量编译错误,我的意思是很多,超过 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

制作命令是:

dan9e@RED MINGW64 ~/cartogrtist/build
$ make -j1 1> error.log 2> error.log

CMAKE_VERBOSE_MAKEFILE 在 CMake 中设置为 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。这显然是不正确的,因为标准库 header <clocale> 不应包含标准库 header 目录之外的任何内容。

出现此问题是因为您错误地将 /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 中搜索了该名称。