omnet++lemon-graph-library

How to use lemon graph library on Omnet++ projects?


I am trying to design a network(Random Graph) in omnet++ where I want to parse the network nodes using Lemon Graph Library. I have installed the library and it works fine if I try to compile any normal c++ file with nodes and edges in any graph using command line g++ -o file file.cpp/cc -lemon. But when i tried it with one of my omnet++ project(which has nothing in it now) the code is as below

#include <omnetpp.h>
#include <iostream>
#include <lemon/list_graph.h>
using namespace lemon;
using namespace std;

class Facility : public cSimpleModule
{
    protected:
    virtual void initialize();
    virtual void handleMessage(cMessage *msg);

};

Define_Module(Facility);

void Facility :: initialize(){


}

void Facility :: handleMessage(cMessage *msg){

}`

the include headers are in angle brackets(not to be confused with double quotes). So when i build the code I get the following errors:

    Description Resource    Path    Location    Type
‘class cEnvir’ has no member named ‘push_back’  PSUC        line 686, external location: /usr/local/include/lemon/bits/graph_extender.h C/C++ Problem
‘class cEnvir’ has no member named ‘push_back’  PSUC        line 687, external location: /usr/local/include/lemon/bits/graph_extender.h C/C++ Problem
‘test’ does not name a type test.cc /ztest  line 9  C/C++ Problem
invalid use of qualified-name ‘cSimulation::getActiveEnvir’ PSUC        line 69, external location: /home/vijay/omnetpp-4.6/include/cenvir.h    C/C++ Problem
make: *** [out/gcc-debug//psuc.o] Error 1   PSUC            C/C++ Problem
make: *** [out/gcc-debug//test.o] Error 1   ztest           C/C++ Problem
no matching function for call to ‘lemon::AlterationNotifier<lemon::GraphExtender<lemon::ListGraphBase>, lemon::ListGraphBase::Arc>::add(cEnvir&)’   PSUC        line 688, external location: /usr/local/include/lemon/bits/graph_extender.h C/C++ Problem

Why doesn't the Omnet++ code get compatible with Lemon graph Library?


Solution

  • OMNeT++ includes a macro definition for ev in cEnvir.h (which is included from omnetpp.h)

    #define ev  (*cSimulation::getActiveEnvir())
    

    Because you include omnetpp.h before graph_extender.h, this macro is expanded in the library's header file, which conflicts with its use as a variable name in

    ev.push_back(Parent::direct(edge, true));
    

    A simple solution would be to include graph_extender.h before omnetpp.h, so the macro is not yet defined when graph_extender.h is read. If this is not possible, you might have some luck with manually undefining the macro before (and possibly restoring the definition after), as follows.

    #pragma push_macro("ev")
    #undef ev
    #include "graph_extender.h"
    #pragma pop_macro("ev")