我正在尝试在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){
}`
include标题位于尖括号中(不要与双引号混淆)。因此,当我构建代码时,我会收到以下错误:
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图库兼容?
答案 0 :(得分:2)
OMNeT ++在cEnvir.h
中包含ev
的宏定义(包含在omnetpp.h
中)
#define ev (*cSimulation::getActiveEnvir())
由于您在omnetpp.h
之前加入了graph_extender.h
,因此会在库的头文件中展开此宏,这与其在
ev.push_back(Parent::direct(edge, true));
一个简单的解决方案是在graph_extender.h
之前加入omnetpp.h
,因此在读取graph_extender.h
时尚未定义宏。如果这是不可能的,那么您可能会有一些运气,在之前手动取消定义宏(并可能在之后恢复定义),如下所示。
#pragma push_macro("ev")
#undef ev
#include "graph_extender.h"
#pragma pop_macro("ev")