1

我正在尝试在 omnet++ 中设计一个网络(随机图),我想在其中使用 Lemon Graph Library 解析网络节点。我已经安装了该库,如果我尝试使用命令行在任何图形中编译任何带有节点和边的普通 c++ 文件,它工作正常g++ -o file file.cpp/cc -lemon。但是当我用我的一个 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 图形库不兼容?

4

1 回答 1

2

evOMNeT++ 包含in的宏定义cEnvir.h(包含在 中omnetpp.h

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

因为你包含omnetpp.hbefore graph_extender.h,所以这个宏在库的头文件中被扩展,这与它作为变量名的使用冲突

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

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

#pragma push_macro("ev")
#undef ev
#include "graph_extender.h"
#pragma pop_macro("ev")
于 2015-07-21T18:27:22.217 回答