c++ - 初始化 vector 时出现令人讨厌的错误

标签 c++ vector

我只是想制作一个 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;就可以编译了但我不知道那条线有什么问题。它在我的其他项目中完全相同,编译正常。

最佳答案

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

关于c++ - 初始化 vector 时出现令人讨厌的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9857651/

相关文章:

c++ - 从 m 个数组的元素组合中提取 n 个最低的总和,用于巨大的数据集

c++ - std::vector 函数 push_back 中的奇怪段错误

c++ - 为什么允许我为包含常量指针的 vector 分配新地址?

c++ - 如何使用 std::copy() 复制到指向通用字节缓冲区开头的指针的目标?

c++ - 为什么 goto 语句在 C++ 中被视为禁忌?

c++ - Concert 技术中的按列建模 - 列生成

c++ - 调整 C++ std/boost iostreams 以提供对内存块的循环写入

c++ - 用 vector::iterator 或 at() 迭代 STL vector 有什么更快的方法?

c++ - 使用 dgemm/dgemv 的矩阵 vector 积

c++ - 执行时间 : GetFrontBufferData, GetBackBuffer、GetRenderTargetData