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

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

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

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.
Create omnet++ project myproject File->new->OMNeT project->Empty project with 'src' and 'simulations' folders
Veins must be imported into the workspace in order to use it: Import-> Existing projects into workspace->
Add veins to Project->Properties->Project References
Put your .ned and c++/h files in folder src
Put omnetpp.ini and all sumo configuration files in folder simulations
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.

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.

Related

Using static library in current project

I'm facing the error when I'm linking an external library and code with the current project. You will understand the problem by this example.
//foo.h
namespace LMS
{
class foo
{
foo(); //implementation in cpp
foo(int dummy) //implemented here
{
//something
}
};
} // namespace LMS
//foo.cpp
#include"foo.h"
namespace LMS
{
foo::foo()
{
//something
}
} // namespace LMS
//externalProgram.h
#include "foo.h"
LMS::foo *ptr;
ptr = new LMS::foo(); //Linking error: LNK 2019
ptr = new LMS::foo(2); //No error
Now the problem is that the external program doesn't know about the foo.cpp and the implementation of class foo methods in it. I'm currently using VS2019 and using two projects in the same solution. I've tried several ways to correct this but it didn't work out. The current way I'm seeing is to implement all the functions in header files.
EDIT: I've already linked the files!!
You should be able to mark your externalProgram project as dependent on the foo project. This will link foo.o in with external program.
Using the UI you will select this in
Project > Project Dependencies : Depends on ...
If that is correct, then the problem is more subtle, sometimes just a simple typo. At this point you want to use the command line tools to break apart the library and confirm the object files, and break apart the object files and confirm the symbols within. A ten year old SO posting discusses using lib.exe to example the library file. The dumpbin tool has a /symbols option that might also be handy for looking at the actual code generated.

Newbie help for Visual C++ project references

I know next to nothing about C++, except that I have a missing to take someone else's C++ library and wrap it for use by C#. I found a few posts about how to do it, and I'm making my way there, bit by bit. But I've hit a wall at this point.
According to this post I'm supposed to create a new managed C++ project. This I have done, and I added a reference to the project I'm supposed to be wrapping. So my code looks like this:
#include "stdafx.h"
#include "DrmWrapper.h"
#include "../OtherLibrary/drm/adept/src/adept_provider.h"
DrmWrapper::DrmWrapper(dpdrm::DRMProcessorClient * client, dpdev::Device * device)
{
adept::DRMProviderImpl * provider = new adept::DRMProviderImpl();
drm_processor_ = provider->createDRMProcessor(client, device);
}
unsigned DrmWrapper::initSignInWorkflow(unsigned workflows, const dp::String& authProvider, const dp::String& username,
const dp::String& password)
{
return drm_processor_->initSignInWorkflow(workflows, authProvider, username, password);
}
All looks good. But when I try compile my wrapper project, I get an error:
d:\src\drm-wrapper\OtherLibrary\drm\adept\src\adept_provider.h(26): fatal error C1083: Cannot open include file: 'dp_all.h': No such file or directory
Eh...whut? I'm not trying to compile the adept library. That already built fine by itself. I just want to compile my own wrapper project. And the dp_all.h file does exist, in the same folder as adept_provider.h.
Clearly there's some paradigm shift I'm not making from C# to C++; it seems like the code is being rebuilt as if the referenced project's source file were in my project folder.
What's the secret switch to get this working?
You should add ../OtherLibrary/drm/adept/src as one of the places where your project looks for header files (in C++/General/Additional Include Directories).
You should change #include "../OtherLibrary/drm/adept/src/adept_provider.h" to #include "adept_provider.h".
What's happening is that the compiler is looking for dp_all.h relative to your project not to the other project. Compilation is not totally separate in C++, headers files are shared between projects and are recompiled in each project where they are used.

MarbleAbstractPresenter to override Marble InputHandler in Qt

The MarbleAbstractPresenter class is present in the api(https://api.kde.org/4.x-api/kdeedu-apidocs/marble/html/classMarble_1_1MarbleAbstractPresenter.html) as well as the current source code(https://github.com/KDE/marble/blob/master/src/lib/marble/MarbleAbstractPresenter.h), but cannot be added to the Qt project.
#include <marble/MarbleWidgetInputHandler.h> //Works
#include <marble/MarbleAbstractPresenter.h> //No Valid Expression
The MarbleAbstractPresenter file is not in the /export/include/marble/ directory like most of the other .h files. Is there a way to add this file so that it can be read by Qt or is there a different way to create an MarbleAbstractPresenter so that a command like this can run?
MarbleWidgetInputHandler *a = new MyInputHandler(new MarbleAbstractPresenter(new MarbleMap()), mapWidget);

LibTiff.NET - No access to TiffCP Namespace?? (General build issue)

Using Visual Studio 2012
I'm writing an adapter class library to make access to LibTiff.Net's TiffCP utility a little cleaner and less dependent on strings (this utility allows, among other things, a user to extract single pages from multipage tiff images).
I've tried using both pre-built LibTiff and building from source, but once I add the BitMiracle.LibTiff.Net reference to my adapter project, I don't have access to the TiffCP namespace. It seems that, of the five projects in the LibTiff solution, only the LibTiff namespace is being built, and the same BitMiracle.LibTiff.Net dll is being placed in all of the five project's bin/debug folder. I have checked the configuration of the LibTiff solution and all projects are set to build... What am I missing here? Am I going to have to add the actual LibTiff and TiffCP project to my class library to access TiffCP, or is there some way to get a dll that will allow me to access the methods of TiffCP?
Here is a sample from LibTiffs website of how to use the TiffCP tool, but again, it simply isn't working for me given the dlls output from the LibTiff build.
using System;
using System.Diagnostics;
using BitMiracle;
namespace BitMiracle.LibTiff.Samples
{
public static class SplitTiffImage
{
public static void Main()
{
string[] arguments =
{
#"Sample Data\multipage.tif,1",
"SplitTiffImage_2ndPage.tif"
};
TiffCP.Program.Main(arguments); //TiffCP reference not recognized
Process.Start("SplitTiffImage_2ndPage.tif");
}
}
}
You have to add a reference to TiffCP.exe into your project, and it works, TiffCP.exe is in the zip file at http://bitmiracle.com/libtiff/

How to connect to Oracle in C++?

I tried to connect to Oracle using C++ but it is giving me error stating that DBManger.h not found. I have also tried using occi.h but got the same error of not found or No Such Directory.
I have installed Oracle 11g and it contains the OCI Liabraries also.
I located the specififc folders also where the OCI libraries are present . In my system they are at location E:\app\user\product\11.1.0\db_1\OCI\lib\MSVC\vc8.
I have also set the Path starting with Oracle home. But, still my program is not able to find the header files.
Any help would be greatly appreciated? I Googled a lot but found the same solution stating that locate the folder where the OCI libraries are available. I am posting my code below written in Visual Studio 2008:
I have written a very small script and just included the header files. Not even done the connectivity:
#include <occi.h>
#include <iostream>
using namespace oracle::occi;
using namespace std;
class DataBaseConnectionTest
{
public:
void test()
{
cout<<"Hello from test"<<'\n';
}
};
void main()
{
DataBaseConnectionTest *dbc=new DataBaseConnectionTest();
dbc->test();
}
Modify your project properties, add the E:\app...vc8 directory name to the Addition include directories. It's under C++/General. No need to double every \ in that one.
You'll probably need a similar treatment for the OCI library file anyway. The include file is only half the puzzle, the other half is the LIB.
You could consider OTL as alternative to OCI. Then your code could be more portable. I used it many years ago, interfacing SqlServer, and was surprised by the clean design and the raw speed (way faster than MFC+ODBC...). Also, I had a problem and Sergei gave me immediate assistance.