GCC使用虚函数编译错误

时间:2015-11-12 00:18:45

标签: c++ gcc abstract-class

在使用GCC编译我的简单C ++程序时遇到了一个奇怪的错误,这里是详细信息:

我有一个名为ware的抽象类,它有一个名为run()虚函数router类实现了这个抽象类。我用make编译它们,我得到一个奇怪的错误。让我们看看下面的所有代码:

ware.h

class ware {
public:
   virtual void run() = 0;
};

router.h

#include "ware.h"

class router: ware {
public:
    void run();
};

router.cc

#include "router.h"

void router::run() {
    // do something
}

这是我的makefile

all: clean build

build:
  gcc router.cc main.cc -o main

clean:
  rm -rf main

当我尝试编译时,我收到了这个错误:

gcc router.cc main.cc -o main
Undefined symbols for architecture x86_64:
  "vtable for __cxxabiv1::__class_type_info", referenced from:
      typeinfo for ware in router-da2a57.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "vtable for __cxxabiv1::__vmi_class_type_info", referenced from:
      typeinfo for router in router-da2a57.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [build] Error 1

任何人都可以帮我查看一下并告诉我我做错了什么吗?在makefile中配置GCC时,我是否犯了错误?

非常感谢你:(

0 个答案:

没有答案