I need to implement a custom protocol on Omnet where I need to know all neighbours from a given device D. I figured that D could be an AodvRouter from Inet since it already has a RoutingTable. I extended AodvRouter (see code below), but I keep having undefined reference to 'typeinfo for inet::IIpv4RoutingTable'
(as seen here)
For information, I am on Windows 10, Omnet5.5.1, Inet4.1.1.
What I tried : using a different compiler as mentioned in other answers, it didn't work. My most recent result, in case any warning helps, is :
make MODE=debug all
MyModule.cc
In file included from MyModule.cc:16:
In file included from ./MyModule.h:28:
In file included from ../inet4/src\inet/networklayer/ipv4/Ipv4RoutingTable.h:36:
In file included from ../inet4/src\inet/networklayer/ipv4/IIpv4RoutingTable.h:24:
In file included from ../inet4/src\inet/networklayer/contract/IRoutingTable.h:23:
In file included from ../inet4/src\inet/networklayer/contract/IRoute.h:22:
In file included from ../inet4/src\inet/networklayer/common/InterfaceEntry.h:24:
../inet4/src\inet/common/packet/tag/TagSet.h:103:20: warning: 'inet::TagSet::getNumTags' redeclared inline; 'dllimport' attribute ignored [-Wignored-attributes]
inline int TagSet::getNumTags() const
^
../inet4/src\inet/common/packet/tag/TagSet.h:108:25: warning: 'inet::TagSet::getTag' redeclared inline; 'dllimport' attribute ignored [-Wignored-attributes]
inline cObject *TagSet::getTag(int index) const
^
In file included from MyModule.cc:16:
./MyModule.h:54:5: warning: '/*' within block comment [-Wcomment]
// UDP callback interface /
^
In file included from MyModule.cc:17:
../inet4/src\inet/common/ModuleAccess.h:69:4: warning: 'inet::findModuleFromPar' redeclared without 'dllimport' attribute: previous 'dllimport' ignored [-Winconsistent-dllimport]
T *findModuleFromPar(cPar& par, const cModule *from, bool required)
^
../inet4/src\inet/common/ModuleAccess.h:66:13: note: previous declaration is here
INET_API T *findModuleFromPar(cPar& par, const cModule *from, bool required = true);
^
../inet4/src\inet/common/ModuleAccess.h:66:1: note: previous attribute is here
INET_API T *findModuleFromPar(cPar& par, const cModule *from, bool required = true);
^
../inet4/src\inet/common/INETDefs.h:61:23: note: expanded from macro 'INET_API'
# define INET_API OPP_DLLIMPORT
^
C:/Omnet/omnetpp-5.5.1/include/omnetpp/platdep/platdefs.h:33:37: note: expanded from macro 'OPP_DLLIMPORT'
# define OPP_DLLIMPORT __declspec(dllimport)
^
In file included from MyModule.cc:17:
../inet4/src\inet/common/ModuleAccess.h:98:4: warning: 'inet::getModuleFromPar' redeclared without 'dllimport' attribute: previous 'dllimport' ignored [-Winconsistent-dllimport]
T *getModuleFromPar(cPar& par, const cModule *from, bool required)
^
../inet4/src\inet/common/ModuleAccess.h:95:13: note: previous declaration is here
INET_API T *getModuleFromPar(cPar& par, const cModule *from, bool required = true);
^
../inet4/src\inet/common/ModuleAccess.h:95:1: note: previous attribute is here
INET_API T *getModuleFromPar(cPar& par, const cModule *from, bool required = true);
^
../inet4/src\inet/common/INETDefs.h:61:23: note: expanded from macro 'INET_API'
# define INET_API OPP_DLLIMPORT
^
C:/Omnet/omnetpp-5.5.1/include/omnetpp/platdep/platdefs.h:33:37: note: expanded from macro 'OPP_DLLIMPORT'
# define OPP_DLLIMPORT __declspec(dllimport)
^
5 warnings generated.
Creating executable: out/gcc-debug//project_dbg.exe
clang++.exe: warning: argument unused during compilation: '-shared-libgcc' [-Wunused-command-line-argument]
out/gcc-debug//MyModule.o:(.rdata[_ZTIN4inet16Ipv4RoutingTableE]+0x28) : référence indéfinie vers « typeinfo for inet::IIpv4RoutingTable »
out/gcc-debug//MyModule.o:(.rdata[_ZTIN4inet16Ipv4RoutingTableE]+0x48) : référence indéfinie vers « typeinfo for inet::ILifecycle »
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:101: out/gcc-debug//project_dbg.exe] Error 1
"make MODE=debug all" terminated with exit code 2. Build might be incomplete.
MyModule.ned
import inet.applications.contract.IApp;
import inet.networklayer.ipv4.Ipv4RouteTable;
@namespace(inet);
simple MyModule like IApp{
parameters:
@class("MyModule");
string routingTableModule = default("^.ipv4.routingTable");
//string interfaceTableModule = default("^.interfaceTable");
//string networkProtocolModule = default("^.ipv4.ip");
gates:
input socketIn;
output socketOut;
}
MyNode.ned
@namespace(inet);
import inet.node.aodv.AodvRouter;
module MyNode extends AodvRouter
{
submodules:
myModule: MyModule;
connections:
myModule.socketOut --> at.in++;
myModule.socketIn <-- at.out++;
}
MyModule.cc
#include "MyModule.h"
#include "inet/common/ModuleAccess.h"
namespace inet {
Define_Module(MyModule);
void MyModule::initialize(){
routingTable = getModuleFromPar<Ipv4RoutingTable>(par("routingTableModule"), this);
}
MyModule::MyModule() {
// TODO Auto-generated constructor stub
}
MyModule::~MyModule() {
// TODO Auto-generated destructor stub
}
} // namespace inet
MyModule.h
#ifndef MYMODULE_H_
#define MYMODULE_H_
#define BUILDING_DLL
#include <map>
#include "inet/networklayer/ipv4/Ipv4RoutingTable.h"
#include <omnetpp.h>
namespace inet {
class MyModule: public omnetpp::cSimpleModule {
protected:
Ipv4RoutingTable *routingTable = nullptr;
virtual void initialize();
virtual void handleMessage(omnetpp::cMessage *msg){};
public:
MyModule();
virtual ~MyModule();
};
} // namespace inet
#endif /* MYMODULE_H_ */
I'd like a solution to make this work, or any other suggestion to obtain the neighbours list.
I must disagree with the duplicate tag quoting How to extend different Modules of Inet with custom messages?: the question is not about the type of error (linking of course) but rather how to make it work under the omnet environment.