与 MinGW STL 的 Clang (错误:全局命名空间中没有名为 'fgetws' 的成员)

Clang with MinGW STL (Error: no member named 'fgetws' in the global namespace)

本文关键字:成员 fgetws Clang STL MinGW 错误 命名空间 全局      更新时间:2023-10-16

我试图在windows下使用MinGW STL (Clang和MinGW的最新版本)编译一个简单的dll。正如你所看到的,我已经禁用了ms兼容模式和硬编码的VS头文件。当我包含MinGW STL映射头时,我得到以下错误:

C:Program Files (x86)LLVMvc11binDebug>clang++ -fno-ms-compatibility -nostdinc -c -shared -v -o simple.o simple.cpp -I "C:MinGWincludesys" -I "C:MinGWlibgcci686-pc-mingw324.8.0include" -I "C:MinGWinclude" -I "C:MinGWincludec++" -I "C:MinGWincludec++4.8.0" -I "C:MinGWincludec++4.8.0backward" -I "C:MinGWincludec++4.8.0bits" -I "C:MinGWincludec++4.8.0debug" -I "C:MinGWincludec++4.8.0decimal" -I "C:MinGWincludec++4.8.0ext" -I "C:MinGWincludec++4.8.0i686-pc-mingw32" -I "C:MinGWincludec++4.8.0tr1" -I "C:MinGWincludec++4.8.0tr2" -I "C:MinGWincludec++4.8.0profile" -Wl,--verbose
clang version 3.4 (trunk)
Target: i686-pc-win32
Thread model: posix
clang++.exe: warning: -Wl,--verbose: 'linker' input unused
clang++.exe: warning: argument unused during compilation: '-shared'
 "C:/Program Files (x86)/LLVM/vc11/bin/Debug/clang++.exe" -cc1 -triple i686-pc-win32 -emit-obj -mrelax-all -disable-free -main-file-name simple.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -target-cpu pentium4 -v -coverage-file simple.o -nostdsysteminc -nobuiltininc -resource-dir "C:/Program Files (x86)/LLVM/vc11/bin/Debug\..\lib\clang\3.4" -I "C:\MinGW\include\sys" -I "C:\MinGW\lib\gcc\i686-pc-mingw32\4.8.0\include" -I "C:\MinGW\include" -I "C:\MinGW\include\c++" -I "C:\MinGW\include\c++\4.8.0" -I "C:\MinGW\include\c++\4.8.0\backward" -I "C:\MinGW\include\c++\4.8.0\bits" -I "C:\MinGW\include\c++\4.8.0\debug" -I "C:\MinGW\include\c++\4.8.0\decimal" -I "C:\MinGW\include\c++\4.8.0\ext" -I "C:\MinGW\include\c++\4.8.0\i686-pc-mingw32" -I "C:\MinGW\include\c++\4.8.0\tr1" -I "C:\MinGW\include\c++\4.8.0\tr2" -I "C:\MinGW\include\c++\4.8.0\profile" -std=c++11 -fdeprecated-macro -ferror-limit 19 -fmessage-length 150 -mstackrealign -fms-extensions -fmsc-version=1300 -fdelayed-template-parsing -fobjc-runtime=gcc -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -backend-option -vectorize-loops -o simple.o -x c++ simple.cpp
clang -cc1 version 3.4 based upon LLVM 3.4svn default target i686-pc-win32
#include "..." search starts here:
#include <...> search starts here:
 C:MinGWincludesys
 C:MinGWlibgcci686-pc-mingw324.8.0include
 C:MinGWinclude
 C:MinGWincludec++
 C:MinGWincludec++4.8.0
 C:MinGWincludec++4.8.0backward
 C:MinGWincludec++4.8.0bits
 C:MinGWincludec++4.8.0debug
 C:MinGWincludec++4.8.0decimal
 C:MinGWincludec++4.8.0ext
 C:MinGWincludec++4.8.0i686-pc-mingw32
 C:MinGWincludec++4.8.0tr1
 C:MinGWincludec++4.8.0tr2
 C:MinGWincludec++4.8.0profile
End of search list.
In file included from simple.cpp:3:
In file included from C:MinGWincludec++4.8.0map:61:
In file included from C:MinGWincludec++4.8.0bits/stl_map.h:63:
In file included from C:MinGWincludec++4.8.0tuple:39:
In file included from C:MinGWincludec++4.8.0array:38:
In file included from C:MinGWincludec++4.8.0stdexcept:39:
In file included from C:MinGWincludec++4.8.0string:40:
In file included from C:MinGWincludec++4.8.0bits/char_traits.h:40:
In file included from C:MinGWincludec++4.8.0bits/postypes.h:40:
C:MinGWincludec++4.8.0cwchar:143:11: error: no member named 'fgetws' in the global namespace
  using ::fgetws;
        ~~^
C:MinGWincludec++4.8.0cwchar:145:11: error: no member named 'fputws' in the global namespace
  using ::fputws;
        ~~^
C:MinGWincludec++4.8.0cwchar:149:11: error: no member named 'getwc' in the global namespace
  using ::getwc;
        ~~^
C:MinGWincludec++4.8.0cwchar:150:11: error: no member named 'getwchar' in the global namespace
  using ::getwchar;
        ~~^
C:MinGWincludec++4.8.0cwchar:155:11: error: no member named 'putwc' in the global namespace
  using ::putwc;
        ~~^
C:MinGWincludec++4.8.0cwchar:156:11: error: no member named 'putwchar' in the global namespace
  using ::putwchar;
        ~~^
6 errors generated.

任何帮助都是感激的!

这些函数在定义__MSVCRT__宏时在MinGW的stdio.h和/或wchar.h中声明。MinGW编译器在构建msvcrt.dll运行时而不是旧的crtdll运行时(我认为几乎从未使用过)定义__MSVCRT__

我不知道clang是否会定义这个宏,或者在什么条件下它会定义(甚至clang是否会链接到msvcrt.dll)。

您可以尝试在clang命令行中添加-D__MSVCRT__=1,看看是否可以正常工作。