c++ mingw STL installation

c++ mingw STL installation

本文关键字:installation STL mingw c++      更新时间:2023-10-16

我最近在我的Windows 32机器上安装了MinGW和MSYS,它似乎运行得很好。

在C++编译器上,我包含了一个向量容器,并且没有任何错误。但当我尝试使用它时,我会遇到编译时错误。

所以,代码

#include <vector>  // include vector.h  
#include <stdio.h>  // include stdio.h
using namespace std;
main()  {
//   vector<int> A;  
printf("nHeya ..");
}

运行良好。然而,当我取消注释第8行——矢量声明行时,我在编译时间中得到了以下错误(缩短):

undefined reference to 'operator delete(void*)'
undefined reference to '__gxx_personality_v0'

您可能使用gcc而不是g++进行编译。实际的编译器是相同的,但g++告诉链接器使用默认的C++库,而gcc只是告诉它查看C库。一旦使用了标准库中特定于C++的部分,gcc就会失败。

顺便说一句,C++不支持旧C中的default int规则,所以您应该从main中指定返回类型。

我不知道您是如何编译代码的。您的主方法无效,签名不正确,并且没有返回任何内容。

应该是这样的:

#include <vector>  // include vector.h  
#include <stdio.h>  // include stdio.h
using namespace std;
int main(int, char**)  {
//   vector<int> A;  
printf("nHeya ..");
return 0;
}

此外,您需要使用g++而不是gcc来编译它。