【问题标题】:How to use lemon graph library on Omnet++ projects?如何在 Omnet++ 项目中使用柠檬图库?
【发布时间】:2015-07-20 22:33:07
【问题描述】:

我正在尝试在 omnet++ 中设计一个网络(随机图),我想在其中使用 Lemon Graph Library 解析网络节点。我已经安装了该库,如果我尝试使用命令行g++ -o file file.cpp/cc -lemon 在任何图形中编译任何带有节点和边的普通 c++ 文件,它工作正常。但是当我用我的一个 omnet++ 项目(现在什么都没有)尝试它时,代码如下

#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){

}`

包含头在尖括号中(不要与双引号混淆)。因此,当我构建代码时,会出现以下错误:

    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

为什么 Omnet++ 代码不兼容 Lemon 图形库?

【问题讨论】:

标签: omnet++ lemon-graph-library


【解决方案1】:

OMNeT++ 在cEnvir.h 中包含ev 的宏定义(包含在omnetpp.h 中)

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

因为你在graph_extender.h之前包含了omnetpp.h,所以这个宏在库的头文件中被展开,这和它在中用作变量名冲突

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

一个简单的解决方案是在omnetpp.h 之前包含graph_extender.h,因此在读取graph_extender.h 时尚未定义宏。如果这是不可能的,您可能会在之前手动取消定义宏(并可能在之后恢复定义),如下所示。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多