NS2中 #include <wireless-phy.h> 引发的问题
NS2中,如果想要引用WirelessPhy类,我们需要#include <wireless-phy.h>,编译的时候,会报出很多错误
错误原因如下:
"In file wireless-phy.h, line enum ChannelStatus { SLEEP, IDLE, RECV, SEND };跟
In file cmu-trace.h, there are two lines: #define RECV .. #define SEND.."
这两次定义是冲突的,从而导致未定义等等错误(4个错误以上)
修改方法:
将其中之一换一个名字,比如:
修改wireless-phy.h/c中的{ SLEEP, IDLE, RECV, SEND }为{ SLEEP, IDLE, RRECV, SSEND }; 以及对应的 c文件中的引用(好像只有一次使用)即可
貌似改这个枚举类型需要改动的地方比较少,只有这两个文件中引用。而cmu-trace.h中的那两个宏的使用我未查询过,有待考证比较
附:
可能报的错误: 碰到类似错误的童鞋可以参考一下
./mac/wireless-phy.h: At global scope:
./mac/wireless-phy.h:130: error: expected identifier before 'r'
./mac/wireless-phy.h:130: error: expected ‘}’ before 'r'
./mac/wireless-phy.h:130: error: expected unqualified-id before 'r'
./mac/wireless-phy.h: In member function ‘bool& WirelessPhy::Is_node_on()’:
./mac/wireless-phy.h:97: error: ‘node_on_’ was not declared in this scope
./mac/wireless-phy.h: In member function ‘bool WirelessPhy::Is_sleeping()’:
./mac/wireless-phy.h:98: error: ‘status_’ was not declared in this scope
./mac/wireless-phy.h: At global scope:
./mac/wireless-phy.h:132: error: no matching function for call to ‘Sleep_Timer::Sleep_Timer()’
./mac/wireless-phy.h:58: note: candidates are: Sleep_Timer::Sleep_Timer(WirelessPhy*)
./mac/wireless-phy.h:56: note: Sleep_Timer::Sleep_Timer(const Sleep_Timer&)
./mac/wireless-phy.h: In function ‘int initialized()’:
./mac/wireless-phy.h:137: error: ‘node_’ was not declared in this scope
./mac/wireless-phy.h:137: error: ‘uptarget_’ was not declared in this scope
./mac/wireless-phy.h:137: error: ‘downtarget_’ was not declared in this scope
./mac/wireless-phy.h:137: error: ‘propagation_’ was not declared in this scope
./mac/wireless-phy.h: In function ‘EnergyModel* em()’:
./mac/wireless-phy.h:143: error: ‘node’ was not declared in this scope
./mac/wireless-phy.h: At global scope:
./mac/wireless-phy.h:147: error: expected declaration before ‘}’ token
make: *** [aodv/aodv.o] 错误 1