0

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.

Lou_is
  • 259
  • 3
  • 11
  • 1
    This is not a duplicate, as the missing typeinfo error is specifically related to a bug in clang. You should either use g++ to compile your project (change PREFER_CLANG in omnet's configure.user file). I have just implemented a workaround in INET master if you want to keep using clang. https://github.com/inet-framework/inet/commit/505af4d10f32d0a3aa505dabbe1ed68bdbb2a6da The related issue is here: https://github.com/inet-framework/inet/issues/379 – Rudi Aug 21 '19 at 10:16
  • In configure.user, CC is set to gcc and the line `PREFER_CLANG=yes` is commented. Reading the comment above it, I assumed that clang was **not** preferred. Do I have to explicitly set it to no ? – Lou_is Aug 21 '19 at 11:38
  • Yes. The default value is is YES for that setting in recent versions of omnet. Don't forget to clean your installation and re-run ./configure and then rebuild. EVerything must be re-built with gcc (including omnet and INET) – Rudi Aug 21 '19 at 13:01
  • I will try this, thank you. However, I fill like the comment surrounding this configure option is not clear and should be updated. – Lou_is Aug 21 '19 at 14:18
  • True, the comment was not updated when the default has changed. Updated it now for OMNeT++ 6 – Rudi Aug 21 '19 at 15:14

1 Answers1

0

This is a CLANG problem on Windows. Either :

  • use the latest version of master
  • use the v3.x branch
  • build omnet and INET with GCC instead of CLANG by changing configure.user with CC=gcc and PREFER_CLANG=no
Lou_is
  • 259
  • 3
  • 11
Rudi
  • 6,418
  • 1
  • 16
  • 20