1

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 Answers1

0

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 objects

C++ requires information about types to be written out in order to implement dynamic_cast, typeid and exception handling. For polymorphic classes (classes with virtual functions), the type_info object is written out along with the vtable so that dynamic_cast can determine the dynamic type of a class object at run time. For all other types, we write out the type_info object when it is used: when applying typeid 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.

Michael Kirsche
  • 901
  • 7
  • 14
  • Thank you for your answer. However, I've just realized that I mentioned different error in the original post. The error I am actually trying to solve reads `"undefined reference to typeinfo for inet::ApplicationBase"`. So my question is, should I declare all functions from ApplicationBase class in my own class? – Lukáš Wisi Nov 29 '17 at 15:35
  • Why not `extends ApplicationBase`? The infos from my response still stand, take a look at the implementation of `UDPBasicApp`, it extends the `ApplicationBase` class and implements the pure virtual functions. – Michael Kirsche Nov 30 '17 at 11:33