Skip to content

Undefined symbols “vtable for …” and “typeinfo for…”

我的经历

编译生成了so,通过ldd -r进行检查,发现了undefined symbol:

undefined symbol: _ZTIN13UstDerivative17CHSAMUSTTraderApiE  (../../../../../lib/libHSAMUSTTraderApi.so)

使用c++filt进行检查:

c++filt _ZTIN13UstDerivative17CHSAMUSTTraderApiE
typeinfo for UstDerivative::CHSAMUSTTraderApi

于是Google: "c++ undefined symbol typeinfo",在 stackoverflow Undefined symbols “vtable for …” and “typeinfo for…”? # A 中,找到了问题症结所在: 我没有将abstract base class的virtual function声明为pure virtual method。

stackoverflow Undefined symbols “vtable for …” and “typeinfo for…”?

A

If Obstacle is an abstract base class, then make sure you declare all its virtual methods "pure virtual":

virtual void Method() = 0;

The = 0 tells the compiler that this method must be overridden by a derived class, and might not have its own implementation.

If the class contains any non-pure virtual functions, then the compiler will assume that they have an implementation somewhere, and its internal structures (vtable and typeinfo) might be generated in the same object file as one of those; if those functions are not implemented, then the internal structures will be missing and you will get these errors.

TODO

stackoverflow Undefined reference to typeinfo for class' and undefined reference tovtable for class' [duplicate]

stackoverflow g++ undefined reference to typeinfo

stackoverflow C++: what are the causes of “ undefined reference to 'typeinfo for [class name]' ”other than virtual functions

generacodice g++ undefined reference to typeinfo

wellho undefined reference to typeinfo - C++ error message