Ubuntu上安装ns2-2.34
步骤1
下载ns-allinone-2.34
$ tar zxf ns-allinone-2.34.tar.gz
步骤2
sudo apt-get install build-essential # GCC
sudo apt-get install tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev # for TCL and TK
sudo apt-get install libxmu-dev libxmu-headers # for nam
步骤3
./install
出现的错误
问题1
ld -shared-o libotcl.so otcl.o
otcl.o: Infunction `OTclDispatch':
/usr/ns-allinone-2.34/otcl-1.13/otcl.c:495:undefined reference to `__stack_chk_fail_local'
otcl.o: Infunction `Otcl_Init':
/usr/ns-allinone-2.34/otcl-1.13/otcl.c:2284:undefined reference to `__stack_chk_fail_local'
ld:libotcl.so: hidden symbol `__stack_chk_fail_local' isn'tdefined
ld: finallink failed: Nonrepresentable section on output
make: ***[libotcl.so]错误1
otcl-1.13make failed! Exiting ...
$ cd ns-allinone-2.34/otcl-1.13
$ gedit configure.in
把77行处的:
SHLIB_LD="ld -shared",
改为;
SHLIB_LD="gcc -shared"
$ gedit configure
将6304行处的:
SHLIB_LD="ld -shared"
改为:
SHLIB_LD="gcc -shared"
问题2
tools/ranvar.cc: In member function ‘virtual double GammaRandomVariable::value()’:
tools/ranvar.cc:219:70: error: cannot call constructor ‘GammaRandomVariable::GammaRandomVariable’ directly
tools/ranvar.cc:219:70: error: for a function-style cast, remove the redundant ‘::GammaRandomVariable’
make: *** [tools/ranvar.o]错误1
Ns make failed!
See http://www.isi.edu/nsnam/ns/ns-problems.html for problems
在ns-allinone-2.33/ ns-2.33/tools文件夹下,找到报错提示中的ranvar.cc文件,打开找到对应的219行删除::GaammaRandomVariable,保存,
即:将219行的
return GammaRandomVariable::GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);
改为:
return GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);
问题3
mac/mac-802_11Ext.h: In member function ‘u_int32_t PHY_MIBExt::getHdrLen11()’:
mac/mac-802_11Ext.h:176:19: error: expected primary-expression before ‘struct’
mac/mac-802_11Ext.h:176:41: error: ‘dh_body’ was not declared in this scope
mac/mac-802_11Ext.h:176:51: error: ‘offsetof’ was not declared in this scope
在ns-allinone-2.34
s-2.34macmac-802_11Ext.h 文件添加#include <cstddef>
然后重新安装
问题4
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
mobile/nakagami.cc:183:73: error: for a function-style cast, remove the redundant ‘::ErlangRandomVariable’
mobile/nakagami.cc:185:67: error: cannot call constructor ‘GammaRandomVariable::GammaRandomVariable’ directly
mobile/nakagami.cc:185:67: error: for a function-style cast, remove the redundant ‘::GammaRandomVariable’
在ns-allinone-2.34/ ns-2.34/ mobile文件夹下,找到报错提示中的nakagami.cc文件,打开找到对应的183行删除::ErlangRandomVariable,保存,
即:将183行的
resultPower = ErlangRandomVariable::ErlangRandomVariable(Pr/m, int_m).value();
改为:
resultPower = ErlangRandomVariable(Pr/m, int_m).value();
在ns-allinone-2.34/ ns-2.34/ mobile文件夹下,找到报错提示中的nakagami.cc文件,打开找到对应的185行删除::GammaRandomVariable,保存,
即:将185行的
resultPower = GammaRandomVariable::GammaRandomVariable(m, Pr/m).value();
改为:
resultPower = GammaRandomVariable(m, Pr/m).value();
步骤4
设置环境变量
# gedit ~/.bashrc
export LD_LIBRARY_PATH=/root/NS2/ns-allinone-2.34/otcl-1.13:/root/NS2/ns-allinone-2.34/lib:$LD_LIBRARY_PATH
export TCL_LIBRARY=/root/NS2/ns-allinone-2.34/tcl8.4.18/library
export PATH=/root/NS2/ns-allinone-2.34/bin:/root/NS2/ns-allinone-2.34/tcl8.4.18/unix:/root/NS2/ns-allinone-2.34/tk8.4.18/unix:$PATH