问题
During the build of my new OMNeT++
project I have encountered following error:
out/clang-debug//myUdp.o:(.rdata[_ZTI5myUdp]+0x10): undefined reference to 'typeinfo for inet::ApplicationBase'
I have already configured INET
reference (Project "myUdp" -> Properties -> Project reference -> inet checkbox selected)
This is INET Makemake configuration: Target tab and Compile tab
This is Makemake configuration of my project (myUdp): Compile tab and Link tab
And the C++ code:
MyUdp.cc
#include <inet/applications/udpapp/UDPBasicApp.h>
class myUdp: public inet::UDPBasicApp {
};
Define_Module(myUdp);
MyUdp.ned
import inet.applications.udpapp.UDPBasicApp;
simple myUdp extends UDPBasicApp {
@class(myUdp);
}
Can somebody help me to solve this error?
回答1:
That is probably because UDPBasicApp's methods are defined as virtual
.
Compare the GCC infos on "vague linking" from http://gcc.gnu.org/onlinedocs/gcc/Vague-Linkage.html, for example this part:
type_info
objectsC++ requires information about types to be written out in order to implement
dynamic_cast
,typeid
and exception handling. For polymorphic classes (classes withvirtual
functions), thetype_info
object is written out along with the vtable so thatdynamic_cast
can determine the dynamic type of a class object at run time. For all other types, we write out thetype_info
object when it is used: when applyingtypeid
to an expression, throwing an object, or referring to a type in a catch clause or exception specification.
You would need to provide either a definition for the virtual functions in the base class (UDPBasicApp) or declare them pure, because the compiler (GCC or Clang in your case) is trying to determine the right method for the translation unit (where the vtable and typeinfo objects are then created) and it cannot determine it correctly apparently.
来源:https://stackoverflow.com/questions/47514350/omnet-issue-with-linking-inet