OMNeT++: Error in module during network setup: Class not found

a 夏天 提交于 2021-01-24 08:47:05

问题


I created my first OMNeT++/veins project, but can’t start the simulation. Can you help me?

I would like to change my question - is there a simple way to create a project, similar to RSUExampleScenario of veins, not under veins/examples/myfolder, but in a separate project and workspace? And what steps must I do for it?

I wanted to create a project similar to RSUExampleScenario from veins, but with other scenario and using other OMNeT++ modules. As I created my project under veins/examples/myfolder, and put my new .ned files under veins structure, it worked fine.

Now I created new project, including folders with .ned and c++/h files, like folder connection (Connection.ned, Connection.cc, Connection.h, package.ned) and folder node (CloudVehicleScenarioMessage.ned, Cloud.ned) and simulation folder cloudvehiclehi (omnetpp.ini).

When I start a simulation I receive the error:

Error in module (cCompoundModule) CloudVehicleScenarioMessage (id=1) during network setup: Class "Connection" not found -- perhaps its code was not linked in, or the class wasn't registered with Register_Class(), or in the case of modules and channels, with Define_Module()/Define_Channel().

I guess the NED files are loaded, but the classes in c++ files cannot be found, though I used Define_Module. Cloud is just a compound module, without any own c++ implementations, it creates no problems. Connection is a simple module, referring to class Connection.cc, where Define_Module() is called and causes the error while loading. All my folders, like node or connection are included, as I can see under Project->Properties->Paths and Symbols->Includes.

I already tried to rebuild OMNeT++ (as told here https://www.linkedin.com/grp/post/3801609-234767834) and to define namespaces for my classes (as told here Problem in defining a module in omnetpp), but it didn’t help.

I proved my makefile and the folders were linked in (as told here https://groups.google.com/forum/#!topic/omnetpp/Cl48hVgkbQ0).

CloudVehicleScenarioMessage.ned is my network in omnetpp.ini.

nodes/CloudVehicleScenarioMessage.ned:

package cloudbasedcsw.nodes;

import cloudbasedcsw.nodes.ScenarioMobility;
import cloudbasedcsw.nodes.Cloud;
import cloudbasedcsw.connection.Connection;

network CloudVehicleScenarioMessage extends ScenarioMobility
{
@display("bgb=540,555");
submodules:
    cloud[1]: Cloud {
        @display("p=150,140;b=10,10,oval");
    }
    con: Connection {
        @display("p=200,40;b=10,10,oval");
    }
}

ned file of module Connection:

connection/Connection.ned

package cloudbasedcsw.connection;

simple Connection{
    @class(CloudBasedCSW::Connection);
}

Class Connection, which can not be found:

connection/Connection.cc

#include <Connection.h>
#include <VehicleListener.h>
#include <iostream>
using CloudBasedCSW::Connection;

Define_Module(CloudBasedCSW::Connection);

void Connection::initialize(int stage){

}

void Connection::connectToCloud(cModule* node){
}

void Connection::disconnectFromCloud(cModule* node){
}

Connection.h

#ifndef CONNECTION_H_
#define CONNECTION_H_
#include <omnetpp.h>

namespace CloudBasedCSW{

class Connection: public cSimpleModule{
public:
    cModule* scenario;
    void connectToCloud(cModule* node);
    void disconnectFromCloud(cModule* node);
protected:
    virtual void initialize(int stage);
private:
    cModule* cloud;
    int currentId;
    int gateCloudInId;
    int gateCloudOutId;
};

}
#endif /* CONNECTION_H_ */

回答1:


I guess that your class Connection is in CloudBasedCSW C++ namespace. Therefore in Connection.ned you should change @class(Connection); to @class(CloudBasedCSW::Connection);.




回答2:


I managed to create a new project and run it, without this error. So, I will share my tutorial.

How to create a OMNeT++ project, which uses veins.

  1. Create omnet++ project myproject File->new->OMNeT project->Empty project with 'src' and 'simulations' folders
  2. Veins must be imported into the workspace in order to use it: Import-> Existing projects into workspace->
  3. Add veins to Project->Properties->Project References
  4. Put your .ned and c++/h files in folder src
  5. Put omnetpp.ini and all sumo configuration files in folder simulations
  6. Create run configuration simulation, with working directory myproject/simulations and Simulation->Executable->Other: with exe file from /myproject/src/myproject

Remark: Don't use namespaces in your c++ files, corresponding to .ned files, because the classes in c++ files would not be found ( Error in module (cCompoundModule) CloudVehicleScenarioMessage (id=1) during network setup: Class "vehicle" not found ).

For Example you have vehicle.ned and vehicle.cc. vehicle.cc includes a class mynamespace::vehicle. vehicle.ned wouldn't know that vehicle lies under namespace mynamespace. Only if a class is defined in ned file via @class(mynamespace::vehicle), it can be found.




回答3:


A easy way to correct this error is copying the .cc or all c++ files into a veins/src/ folder. Using this technique you compiler recognize you class.



来源:https://stackoverflow.com/questions/31292964/omnet-error-in-module-during-network-setup-class-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!