ns2.34安装bug
一、前言
1)系统信息
hj@ubuntu:~/ns2.34/ns-allinone-2.34/ns-2.34/mobile$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.5 LTS Release: 20.04 Codename: focal hj@ubuntu:~/ns2.34/ns-allinone-2.34/ns-2.34/mobile$ uname -a Linux ubuntu 5.15.0-67-generic #74~20.04.1-Ubuntu SMP Wed Feb 22 14:52:34 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
2)本文是在https://www.cnblogs.com/hjxiamen/p/17115561.html的基础上修复ns2.34在安装时所存在的bug信息。
二、bug1
1) 这个错误提示是在编译NS-2时出现的。其中,tools/ranvar.cc是一个随机变量生成器相关的文件。错误信息的主要原因是在GammaRandomVariable类的成员函数value()中调用了其自身的构造函数GammaRandomVariable::GammaRandomVariable,而C++标准不允许这种方式的构造函数调用。这里需要修改成员函数value()的实现方式,以避免出现这个问题。具体可以参考NS-2官网提供的补丁或者其他相关的修复方法。
2)但是同样的安装方式下,NS-2(2.35可以正常安装),其结果如下所示:
3)为此,考虑的解决方案是对比两个版本中~/ns2.34/ns-allinone-2.34/ns-2.34/tools/ranvar.cc关于GammaRandomVariable类的成员函数value()如何调整
NS-2(2.34) 相关的函数如下所示:
NS-2(2.35)相关的函数如下所示:
在这个错误中,GammaRandomVariable::GammaRandomVariable(1.0 + alpha_, beta_)使用了双冒号作为作用域解析运算符。它意味着调用GammaRandomVariable类的构造函数。
而GammaRandomVariable(1.0 + alpha_, beta_)使用了类的实例化,它不需要使用作用域解析运算符。在这里,GammaRandomVariable是一个类对象,它调用了构造函数并返回一个值。
二、bug2
In file included from mac/mac-802_11Ext.cc:66:0: mac/mac-802_11Ext.h: In member function ‘u_int32_t PHY_MIBExt::getHdrLen11()’: mac/mac-802_11Ext.h:175:19: error: expected primary-expression before ‘struct’ return(offsetof(struct hdr_mac802_11, dh_body[0]) ^ mac/mac-802_11Ext.h:175:41: error: ‘dh_body’ was not declared in this scope return(offsetof(struct hdr_mac802_11, dh_body[0]) ^ mac/mac-802_11Ext.h:175:51: error: ‘offsetof’ was not declared in this scope return(offsetof(struct hdr_mac802_11, dh_body[0]) ^ mac/mac-802_11Ext.h:177:3: warning: control reaches end of non-void function [-Wreturn-type] } ^ make: *** [Makefile:94:mac/mac-802_11Ext.o] 错误 1 Ns make failed!
1)这段报错的原因是因为头文件 stddef.h
中的 offsetof()
宏未被正确包含在代码中。这个宏用于计算结构体中指定成员的偏移量。在~/ns2.34/ns-allinone-2.34/ns-2.34/ mac/mac-802_11Ext.h
文件中,该宏用于计算 hdr_mac802_11
结构体中成员 dh_body
的偏移量。因此,如果未正确包含 stddef.h
头文件,则会导致编译错误。
NS2(2.34)中mac-802_11Ext.h包含的头文件如下所示
NS2(2.35)中mac-802_11Ext.h包含的头文件如下所示
为此,在ns2.34中对应文件添加 #include <stddef.h> ,不会出现此错误
三、bug3
mobile/nakagami.cc: In member function ‘virtual double Nakagami::Pr(PacketStamp*, PacketStamp*, WirelessPhy*)’: mobile/nakagami.cc:183:73: error: cannot call constructor ‘ErlangRandomVariable::ErlangRandomVariable’ directly [-fpermissive] resultPower = ErlangRandomVariable::ErlangRandomVariable(Pr/m, int_m).value(); ^ mobile/nakagami.cc:183:73: error: for a function-style cast, remove the redundant ‘::ErlangRandomVariable’ [-fpermissive] mobile/nakagami.cc:185:67: error: cannot call constructor ‘GammaRandomVariable::GammaRandomVariable’ directly [-fpermissive] resultPower = GammaRandomVariable::GammaRandomVariable(m, Pr/m).value(); ^ mobile/nakagami.cc:185:67: error: for a function-style cast, remove the redundant ‘::GammaRandomVariable’ [-fpermissive] make: *** [Makefile:94:mobile/nakagami.o] 错误 1 Ns make failed!
这段错误显示在文件~/ns2.34/ns-allinone-2.34/ns-2.34/ mobile/nakagami.cc
的第 183 行和第 185 行。这两行代码都是在构造一个随机变量对象,但是语法不正确,导致编译错误。
1)第 183 行的错误信息显示,ErlangRandomVariable::ErlangRandomVariable
构造函数不能直接调用。这个错误信息建议移除冗余的 ::ErlangRandomVariable
,即将 ErlangRandomVariable::ErlangRandomVariable
修改为 ErlangRandomVariable
。
2)第 185 行的错误信息显示,GammaRandomVariable::GammaRandomVariable
构造函数也不能直接调用。建议将 GammaRandomVariable::GammaRandomVariable
修改为 GammaRandomVariable
。
四、结果
1)在解决上述bug之后,我们可以发现终端界面出现我们想看见的界面
Ns-allinone package has been installed successfully. Here are the installation places: tcl8.4.18: /home/hj/ns2.34/ns-allinone-2.34/{bin,include,lib} tk8.4.18: /home/hj/ns2.34/ns-allinone-2.34/{bin,include,lib} otcl: /home/hj/ns2.34/ns-allinone-2.34/otcl-1.13 tclcl: /home/hj/ns2.34/ns-allinone-2.34/tclcl-1.19 ns: /home/hj/ns2.34/ns-allinone-2.34/ns-2.34/ns nam: /home/hj/ns2.34/ns-allinone-2.34/nam-1.14/nam gt-itm: /home/hj/ns2.34/ns-allinone-2.34/itm, edriver, sgb2alt, sgb2ns, sgb2comns, sgb2hierns
之后的步骤可以参考https://www.cnblogs.com/hjxiamen/p/17115561.html完成后续的内容--添加环境变量。