Omnet and Inet linking error : undefined reference to typinfo

Omnet and Inet linking error : undefined reference to typinfo

我需要在 Omnet 上实施自定义协议,我需要从给定设备 D 了解所有邻居 。我认为 D 可能是来自 Inet 的 AodvRouter,因为它已经有一个路由表。我扩展了 AodvRouter(见下面的代码),但我一直有 undefined reference to 'typeinfo for inet::IIpv4RoutingTable'(如 here
参考资料,我在Windows10,Omnet5.5.1,Inet4.1.1.

我试过:使用其他答案中提到的不同编译器,但没有用。如果有任何警告有帮助,我最近的结果是:

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_ */

我想要一个解决方案来完成这项工作,或者任何其他获取邻居列表的建议。

我必须不同意重复标签引用 :问题不在于错误类型(当然是链接),而是如何使其在 omnet 环境下工作。

这是 Windows 上的 CLANG 问题。 要么:

  • 使用最新版本的master
  • 使用 v3.x 分支
  • 通过将 configure.user 更改为 CC=gccPREFER_CLANG=no
  • ,使用 GCC 而不是 CLANG 构建 omnet 和 INET