初始化向量时出现令人讨厌的错误

时间:2012-03-25 03:13:20

标签: c++ vector

我只是想制作一个矢量,但它给了我一个巨大的错误,我正在跟随我的另一个项目的一个工作示例。代码:

#include <stdio.h>
#include <stdlib.h>
#include <vector>
using namespace std;

struct organism {
    bool One;
    bool Two;
};
std::vector<organism> organisms;

int main() {
    printf("Content-type: text/html\n\n");
    printf("TEST");
    printf(getenv("QUERY_STRING"));

    return 0;
}

错误:

> "make" 
C:/MinGW/bin/gcc.exe -o build/e2.exe source/main.cpp
C:\Users\Stephen\AppData\Local\Temp\ccc0a0w2.o:main.cpp:(.text$_ZN9__gnu_cxx13new_allocatorI8organismE10deallocateEPS1_j[__gnu_cxx::new_allocator<organism>::deallocate(organism*, unsigned int)]+0xd): undefined reference to `operator delete(void*)'
C:\Users\Stephen\AppData\Local\Temp\ccc0a0w2.o:main.cpp:(.eh_frame$_ZNSt12_Vector_baseI8organismSaIS0_EED2Ev+0x13): undefined reference to `__gxx_personality_v0'
C:\Users\Stephen\AppData\Local\Temp\ccc0a0w2.o:main.cpp:(.eh_frame$_ZNSt6vectorI8organismSaIS0_EED1Ev+0x13): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
"make": *** [build] Error 1

> Process Exit Code: 2
> Time Taken: 00:01

如果我注释掉std::vector<organism> organisms;,我可以编译它,但我不知道该行有什么问题。在我的其他项目中完全相同,编译得很好。

1 个答案:

答案 0 :(得分:8)

您需要使用g++.exe而不是gcc.exe进行编译,以便知道它需要与C ++库链接。