OMNeT++初学者运行简易项目遇my_node类未找到错误求助
Hey there, let's get that OMNeT++ error sorted out! The problem here is a straightforward mismatch between your NED file and C++ code—OMNeT++ can't connect the my_node module you defined in NED to any C++ class, hence the "not found" message. Let's break down how to fix this quickly.
The Root Cause
Your NED file defines a simple module called my_node, but your C++ code registers a class named CDNClass using Define_Module(CDNClass);. There's no link between these two, so when OMNeT++ tries to set up the network, it can't find the code backing my_node.
Solution 1: Link NED Module to Your C++ Class
The easiest fix is to update your NED file to tell OMNeT++ that my_node should use your CDNClass code. Modify the simple my_node block like this:
simple my_node { @class(CDNClass); // This line connects the NED module to your C++ class gates: input in; output out; }
Alternatively, you can use inheritance (since CDNClass extends cSimpleModule):
simple my_node : CDNClass { gates: input in; output out; }
Solution 2: Align C++ Class Name with NED Module Name
If you prefer, you can rename your C++ class to match the NED module name instead. Update your C++ code like this:
#include <string.h> #include <omnetpp.h> using namespace omnetpp; // Rename the class to match the NED module name class my_node : public cSimpleModule { protected: virtual void initialize() override; virtual void handleMessage(cMessage *msg) override; }; // Register the class with the same name as the NED module Define_Module(my_node); void my_node::initialize(){ if (strcmp("note1",getName())==0) { cMessage *msg = new cMessage("data"); send(msg, "out"); } } void my_node::handleMessage(cMessage *msg){ send(msg,"out"); }
Important Final Step
After making either change, recompile your entire project (click the Build button in OMNeT++ IDE, or run make in the project directory). This ensures the updated code is linked into your simulation executable—skipping this step will leave you with the same error even after fixing the code/NED mismatch.
Also, double-check that your C++ source file is included in the project's build configuration (OMNeT++ usually adds new files automatically, but it's worth confirming if you're still having issues).
内容的提问来源于stack exchange,提问作者vahidtwo

