2015-07-20 72 views
1

我想在omnet ++中設計一個網絡(隨機圖),我想使用檸檬圖庫解析網絡節點。我已經安裝了該庫,如果我嘗試使用命令行g++ -o file file.cpp/cc -lemon在任何圖形中編譯任何具有節點和邊的正常C++文件,它都可以正常工作。但是,當我與我的OMNET ++項目之一(現在在它沒有任何關係),試了一下它的代碼如下如何在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圖庫兼容?

+0

http://stackoverflow.com/questions/19912682/c-error-no-matching-function-for-call-to –

回答

2

的OMNeT ++包括用於cEnvir.hev宏定義(這是從omnetpp.h包括)

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

因爲你包括omnetpp.hgraph_extender.h之前,該宏是在庫的頭文件,這與其作爲利用衝突擴大在

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

變量名的簡單的解決辦法是之前包括,所以當讀取graph_extender.h時宏未定義。如果這是不可能的,你可能會有一些運氣在手動定義宏之前(並且可能在之後恢復定義),如下所示。

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

非常感謝你,它的工作! –

相關問題