简体   繁体   English

MinGW无法包含标准C ++库

[英]Cannot include standard C++ libraries with MinGW

I have a Qt C++ application that compiles fine with the MSVC compiler. 我有一个Qt C ++应用程序,可以使用MSVC编译器很好地进行编译。 Now I'm trying to compile the same application with MinGW so that I can eventually port it to Mac OSX. 现在,我尝试使用MinGW编译同一应用程序,以便最终将其移植到Mac OSX。 However, when doing so I'm getting an error on all the standard includes: 但是,这样做时,我在所有标准上都遇到了错误:

#include <algorithm>
#include <ctime>
#include <map>
#include <sstream>
#include <vector>

And the compiler outputs: 编译器输出:

..\trunk\stable.h:29:21: error: algorithm: No such file or directory
..\trunk\stable.h:30:17: error: ctime: No such file or directory
..\trunk\stable.h:31:15: error: map: No such file or directory
..\trunk\stable.h:32:19: error: sstream: No such file or directory
..\trunk\stable.h:33:18: error: vector: No such file or directory

I really don't understand what could be causing this issue. 我真的不明白是什么原因导致了这个问题。 Any suggestion? 有什么建议吗?

This is one of the more common errors you will see if your source is C++ but is being compiled as C. 如果您的源代码是C ++,但正在被编译为C,则这是较常见的错误之一。

This in turn can happen if the source uses .C (note capital C) extension for C++ files. 如果源对C ++文件使用.C (注意大写C)扩展名,则可能会发生这种情况。 If the source is used in a case-insensitive file system (like all of the windows ones generally) then make probably won't be able to properly tell whether to compile them as C or C++. 如果源代码用于不区分大小写的文件系统(通常与所有Windows窗口系统一样),那么make可能无法正确判断是将其编译为C还是C ++。

By default, make (including the mingw version) will compile C++ source from extensions .C , .cc and .cpp . 默认情况下, make (包括mingw版本)将从扩展名.C.cc.cpp编译C ++源代码。 ( This page has the details). 此页面有详细信息)。

You have 3 options: 您有3种选择:

  • rename your sources to one of the above extensions. 将您的源重命名为上述扩展之一。 generally .cc and .cpp are the easiest to work with. 通常, .cc.cpp是最容易使用的。
  • if ALL of the sources in the makefile , you can go CC=mingw32-g++ mingw32-make -f Makefile.Debug 如果所有源都在makefile ,则可以转到CC=mingw32-g++ mingw32-make -f Makefile.Debug
  • you can add this to the makefile or one of the included files: 您可以将其添加到makefile或包含的文件之一中:

     %.o: %.c++ $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 

    but this will only work if the makefile(s) haven't changed the rules for compilation. 但这仅在makefile没有更改编译规则的情况下才有效。

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

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