How to fix duplicate symbol error in compiling simple module inheriting INET EtherTrafGen class in omnet++? - omnet++

I try to make my own traffic generator module inheriting INET EtherTrafGen in omnet++,
only resulting in duplicate symbol error. I can't figure out the reason.
Below are the compile error messages.
..
Creating executable: ../out/clang-release/src/hdc.exe
lld-link: error: duplicate symbol: inet::OperationalMixin<omnetpp::cSimpleModule>::isUp() const
>>> defined at ../out/clang-release/src/TrafGen.o
>>> defined at libINET.dll
lld-link: error: duplicate symbol: inet::OperationalMixin<omnetpp::cSimpleModule>::isDown() const
>>> defined at ../out/clang-release/src/TrafGen.o
>>> defined at libINET.dll
clang++: error: linker command failed with exit code 1 (use -v to see invocation
..
The corresponding header file, i.e. TrafGen.h is
#include "inet/applications/ethernet/EtherTrafGen.h"
namespace inet {
//class TrafGen : public cSimpleModule ----> In this case, no compile error
class TrafGen : public EtherTrafGen
{
protected:
virtual void initialize() override;
virtual void handleMessage(cMessage *msg) override;
};
}
and the corresponding TrafGen.cc file is
#include "TrafGen.h"
namespace inet {
Define_Module(TrafGen);
void TrafGen::initialize()
{
if (strcmp("hostA", getName()) == 0) {
cMessage *msg = new cMessage("hdcMsg");
send(msg, "out");
}
}
void TrafGen::handleMessage(cMessage *msg)
{
send(msg, "out"); // send out the message
}
}
TrafGen.ned is
import inet.applications.ethernet.EtherTrafGen;
simple TrafGen extends EtherTrafGen
{
parameters:
#class(inet::TrafGen);
}
By the way, when the TrafGen: public 'cSimpleModule' is used instead of 'EtherTrafGen' in the definition of TrafGen in the TrafGen.h, no compile error (duplicate symbol error) occurs.

I changed the PREFER_CLANG of configure.user file as 'no'. Now it seems that the duplicate symbol errors do not occur.

Related

How to include a new message extended from DemoSafetyMessage in the MyVeinsApp application?

I created a new safety messsage that is extended from the DemoSafetyMessage:
import veins.modules.messages.DemoSafetyMessage;
namespace veins;
packet NewSafetyMsg extends DemoSafetyMessage {
double senderAngle;
double PowRxdBmAvg;
}
I include this new message into the MyVeinsApp application and pass it to the onBSM function in both the .cc and .h files of MyVeinsApp.
#include "veins/modules/messages/NewSafetyMsg_m.h"
void onBSM(NewSafetyMsg* bsm) override; // in the .h file
#include "veins/modules/messages/NewSafetyMsg_m.h" //in the .cc file
However, I am getting this error in the .h file.
Description Resource Path Location Type ‘void veins::MyVeinsApp::onBSM(veins::NewSafetyMsg*)’ marked ‘override’, but does not override MyVeinsApp.h /veins/src/veins/modules/application/traci line 50 C/C++ Problem
I know that MyVeinsApp is extending the DemoBaseApplLayer which takes DemoSafetyMessage, So there should be no problem!! What I am doing wrong?
From TraciDemo11p example:
In .h file you need to keep the same method as that of parent class
void onBSM(DemoSafetyMessage* bsm) override;
In .cc file The extended message (i.e. NewSafetyMessage) should be dynamically casted to parent message type (i.e. DemoSafetyMessage)
void MyVeinsApp::onBSM(DemoSafetyMessage* bsm)
{
NewSafetyMessage* bsm1 = check_and_cast<NewSafetyMessage*>(bsm);
......
......
void onBSM(DemoSafetyMessage* bsm) override; //parent class
void onBSM(NewSafetyMsg* bsm) override; //child class
Function overriding in C++ does'nt work with parameter mismatch.

Failing to build a custom Asterisk PJSIP module

I am trying to create a custom Asterisk PJSIP module that can:
1) analyse incoming sip messages
2) print info from sip header into log/console
Here is my code (simplified) :
#include "asterisk.h"
ASTERISK_REGISTER_FILE()
#ifndef AST_MODULE
#define AST_MODULE "res_modul"
#endif
//bunch of libraries here
static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata);
static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata)
{
char *method;
method= rdata->pkt_info.packet;
ast_log(LOG_NOTICE,"SIP METHOD is: %.8s \n",method);
return PJ_SUCCESS;
}
static pjsip_module logging_module = {
.name = { "Test module", 20 },
.priority = 0,
.on_rx_request = logging_on_rx_msg,
.on_rx_response = logging_on_rx_msg,
};
static int load_module(void)
{
CHECK_PJSIP_MODULE_LOADED();
ast_log(AST_LOG_WARNING, "Success in loading!");
ast_sip_register_service(&logging_module);
return AST_MODULE_LOAD_SUCCESS;
}
static int unload_module(void)
{
ast_sip_unregister_service(&logging_module);
return 0;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Test module",
.support_level = AST_MODULE_SUPPORT_EXTENDED,
.load = load_module,
.unload = unload_module,
.load_pri = AST_MODPRI_DEFAULT,
);
When I try to compile Asterisk with my module i get a compilation error:
menuselect/menuselect --check-deps menuselect.makeopts
[CC] res_modul.c -> res_modul.o
[LD] res_modul.o -> res_modul.so
[LD] res_pjsip.o res_pjsip/security_events.o res_pjsip/pjsip_options.o res_pjsip/location.o res_pjsip/config_global.o res_pjsip/pjsip_transport_events.o res_pjsip/presence_xml.o res_pjsip/pjsip_resolver.o res_pjsip/config_system.o res_pjsip/config_domain_aliases.o res_pjsip/config_transport.o res_pjsip/pjsip_distributor.o res_pjsip/pjsip_configuration.o res_pjsip/res_modul.o res_pjsip/pjsip_session.o res_pjsip/pjsip_message_filter.o res_pjsip/pjsip_global_headers.o res_pjsip/pjsip_transport_management.o res_pjsip/pjsip_cli.o res_pjsip/config_auth.o res_pjsip/pjsip_scheduler.o -> res_pjsip.so
res_pjsip/res_modul.o: In function `__internal_res_pjsip_self':
/usr/local/src/asterisk-14.7.6/res/res_pjsip/res_modul.c:136: multiple definition of `__internal_res_pjsip_self'
res_pjsip.o:/usr/local/src/asterisk-14.7.6/res/res_pjsip.c:4918: first defined here
collect2: error: ld returned 1 exit status
I have no idea what causes this, there's no definition of `__internal_res_pjsip_self' in the source code. Not in my module, not in the res_pjsip.c file. According to the compilation error, its defined in res_pjsip.c:4918, but at that line is just the AST_MODULE_INFO.
AST_MODULE_INFO is macros which return function you refer into code.
Read more about C preprocessing and debuging

How to call a method added to the windows native module of Appelerator Platform

We write to ask how to correctly call a method of Titanium Appelerator native module.
Our development environment is as the following:
Titanium SDK :5.2.0
Appcelerator CLI: 5.2.0
TabletPC:Windows10pro
Our module has been developed with the following procedures;
(1) we created a module referring to the document of https://github.com/appcelerator/titanium_mobile_windows#module-development
An additional method aaa() was added to the module.
cd MY_WORKSPACE
ti create -p windows -t module //create a module project
cd MY_MODULE_NAME/windows
ti build -p windows -T ws-local //build my module project
(2) A windows’ application was created to call the above module, and there was no error while we call the module from the application. However, while we call the method aaa(), Titanium error message as the following occurred;
“aaa() method does not exist”.
In the Titanium windows platform for windows10, the dll for module was created correctly. Then, we are just wondering which parts of our source are not correct;
(1) The definition of a method aaa()is not correct.
(2) The source code to call the native module is not correct.
(3) The source code to call the aaa() method is not correct.
We attached our source code as the following and thank you in advance for your comment and advice.
The code is as below.
windows/src/JpNativeModuleExample.cpp
#include "JpNativeModuleExample.hpp"
#include "Titanium/detail/TiImpl.hpp"
namespace Jp
{
NativeModuleExample::NativeModuleExample(const JSContext& js_context) TITANIUM_NOEXCEPT
: JSExportObject(js_context)
{
TITANIUM_LOG_DEBUG("NativeModuleExample::ctor Initialize");
}
void NativeModuleExample::postInitialize(JSObject& js_object)
{
}
void NativeModuleExample::postCallAsConstructor(const JSContext& js_context, const std::vector<JSValue>& arguments)
{
}
//add new method
void NativeModuleExample::aaa() TITANIUM_NOEXCEPT
{
}
void NativeModuleExample::JSExportInitialize()
{
JSExport<NativeModuleExample>::SetClassVersion(1);
JSExport<NativeModuleExample>::SetParent(JSExport<JSExportObject>::Class());
}
}
windows/include/JpNativeModuleExample.hpp
#ifndef _JPNATIVEMODULEEXAMPLE_HPP_
#define _JPNATIVEMODULEEXAMPLE_HPP_
#include "JpNativeModuleExample_EXPORT.h"
#include "Titanium/detail/TiBase.hpp"
#include "Titanium/Module.hpp"
namespace Jp
{
using namespace HAL;
class JPNATIVEMODULEEXAMPLE_EXPORT NativeModuleExample : public JSExportObject, public JSExport<NativeModuleExample>
{
public:
NativeModuleExample(const JSContext&) TITANIUM_NOEXCEPT;
void aaa() TITANIUM_NOEXCEPT;
virtual void postInitialize(JSObject& js_object) override;
virtual void postCallAsConstructor(const JSContext& js_context, const std::vector<JSValue>& arguments) override;
virtual void aaa(); //add new method
virtual ~NativeModuleExample() = default;
NativeModuleExample(const NativeModuleExample&) = default;
NativeModuleExample& operator=(const NativeModuleExample&) = default;
#ifdef TITANIUM_MOVE_CTOR_AND_ASSIGN_DEFAULT_ENABLE
NativeModuleExample(NativeModuleExample&&) = default;
NativeModuleExample& operator=(NativeModuleExample&&) = default;
#endif
static void JSExportInitialize();
};
}
#endif // _JPNATIVEMODULEEXAMPLE_HPP_
sample code
var nativemoduleexample = require('jp.NativeModuleExample');
Ti.API.info("module is => " + nativemoduleexample); //no problem
var aaa = nativemoduleexample.aaa(); //titanium error is displayed
$.index.open();
In order to enable your function, you need to register it using TITANIUM_ADD_FUNCTION at JSExportInitialize(). You might want to check out working examples under TitaniumKit such as Ti.UI.Button and Ti.UI.Window.
void NativeModuleExample::JSExportInitialize()
{
JSExport<NativeModuleExample>::SetClassVersion(1);
JSExport<NativeModuleExample>::SetParent(JSExport<JSExportObject>::Class());
TITANIUM_ADD_FUNCTION(NativeModuleExample, aaa);
}
And then use TITANIUM_FUNCION to define function like this...
TITANIUM_FUNCTION(NativeModuleExample, aaa)
{
aaa();
return get_context().CreateUndefined()
}

How to use the takeScreenshot() method present in TraCICommandInterface.h?

I am trying to do simulation in OMNeT++ and I have used Veins and SUMO as well in the simulation, but I have got this error:
Model error: TraCI Server reported error executing command 0xcc("View
'#0' is not known")..
I am using the header file TraCICommandInterface.h and in that using the below mentioned class
class GuiView {
public:
GuiView(TraCICommandInterface* traci, std::string viewId) : traci(traci), viewId(viewId) {
connection = &traci->connection;
}
void setScheme(std::string name);
void setZoom(double zoom);
void setBoundary(Coord p1, Coord p2);
void takeScreenshot(std::string filename = "");
protected:
TraCICommandInterface* traci;
TraCIConnection* connection;
std::string viewId;
};
GuiView guiView(std::string viewId) {
return GuiView(this, viewId);
}
I am trying to use the takeScreenshot() function but in order to do so first I am creating an object of this class using GuiView guiView(std::string viewId).
So my question is what is viewId?
The viewId refers to which SUMO window to take a screenshot of.
For example, this screenshot
shows five views. Visible in the window titles are their names: here,
they are called View #0 to View #4.

Exceptions w/QtConcurrent::Exception and boost::exception

I want to use an exception hierarchy where the base exception class derives from boost::exception so that I can get the nice and useful diagnostic information that that class has to offer and QtConcurrent::Exception so that I can throw my exceptions across threads.
Hence, my base exception class looks like:
class MyException : public QtConcurrent::Exception, public boost::exception
{
public:
MyException() { };
virtual ~MyException() throw() { }
// required by QtConcurrent::Exception to be implemented
virtual void raise() const { throw *this; }
virtual MyException* clone() const { return new MyException(*this); }
};
Per QtConcurrent::Exception's documentation, raise() and clone() must be implemented in any class derived from QtConcurrent::Exception. So, the rest of my code may look something like:
void foo()
{
BOOST_THROW_EXCEPTION(MyException());
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
try
{
foo();
}
catch (const MyException& me)
{
std::cerr << boost::diagnostic_information(me);
}
return 0;
}
However, using the BOOST_THROW_EXCEPTION() macro causes the following compilation error:
error C2555: 'boost::exception_detail::clone_impl::clone':
overriding virtual function return type differs and is not covariant
from 'MyException::clone'
I am not entirely sure what this error is telling me (my fault, not the errors, I'm sure!).
If I instead use throw MyException(); the code compiles just fine. As I mentioned above, I'd like to use BOOST_THROW_EXCEPTION() so that I get the diagnostic information in my exceptions.
I know that one possible work-around could be another class derived from just QtConcurrent::Exception that has a boost::exception member, essentially a container for the actual error. But if possible, I would like to continue to have the MyException class inherit from both QtConcurrent::Exception and boost::exception.
Can someone offer some insight into what the error is saying? Is there any way to accomplish what I want?

Resources