linker command failed with exit code 1

报错内容(80年不写C++,连虚函数是啥都忘了hhhh)

Undefined symbols for architecture arm64:
  "IDPairAccum::run()", referenced from:
      _main in main.o
  "IDPairAccum::~IDPairAccum()", referenced from:
      _main in main.o
      _main in main.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

链接器找不到 IDPairAccum 类的析构函数 ~IDPairAccum() 和成员函数 run() 的定义。错误信息表明,这两个符号在arm64 架构下未定义,导致链接器无法完成链接过程。

通俗点儿说,就是它能看到你的函数声明,却看不到你的函数内容(函数定义),也就是没有找到你的函数实现内容,一种可能是真的没有实现,另一种可能是 g++ 编译的时候没有吧这个函数加上。

以上情况是有声明没实现,那要是连声明都没有,报什么错呢?

显然他只会报:

xxx.cpp:18:1: error: use of undeclared identifier 'IDPairAccum'
IDPairAccum::IDPairAccum(
^

值得一提的是,如果虚析构函数只有声明,没有实现,他的报错是这样的

Undefined symbols for architecture arm64:
  "IDPairAccum::~IDPairAccum()", referenced from:
      _main in main.o
      _main in main.o
  "vtable for IDPairAccum", referenced from:
      IDPairAccum::IDPairAccum(...) in xxx.o
   NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

链接器指出 vtable for IDPairAccum 未定义。

这通常意味着 IDPairAccum 类中声明了虚函数,但是没有为这些虚函数提供定义(实现)。
虚函数表(vtable)是编译器为每个含有虚函数的类生成的一个表,它用于支持动态绑定。

如果类中的第一个非内联虚函数没有定义,链接器就会找不到这个vtable,导致链接错误。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值