http://blog.sina.com.cn/s/blog_6ddfdc6701018fk1.html
最近一直在使用ns2,遇到各种问题,需要各种重装,特此整理一下安装过程。
首先下载到ns-allinone-2.34.tar.gz,这个网上到处都是。
然后开始在终端里输入命令,获取ns2需要的相关软件:
sudo apt-get install build-essential
sudo apt-get install tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev
sudo apt-get install libxmu-dev libxmu-headers
sudo apt-get install xorg-dev g++ xgraph
sudo apt-get install g++-4.4
===============================
然后解压ns-allinone-2.34.tar.gz,放到你指定的目录。
检查你的gcc版本,如果gcc版本大于4.0(大部分人的都是,建议直接改),要在执行./install之前作出一些修改。
gcc4.0版本以前是用ld-share来生成共享库的,但是到了4.0以上的版本,这个命令改为了gcc-share。
修改命令如下:
cdns-allinone-2.34/otcl-1.13
sudogedit configure.in
把77行处的
SHLIB_LD="ld-shared"
改为
SHLIB_LD="gcc-shared"
保存退出,然后
sudogedit configure
把6304行(Ctrl+i跳到6304行)的
SHLIB_LD="ld-shared"
改为
SHLIB_LD="gcc-shared"
保存退出,然后
cdns-allinone-2.34 #到安装目录
sudo./install #开始安装
如果没有更改直接安装,就会出现这样的错误:
ld:
ld:
make:
这只是有可能出现的第一个错误,接下来还有更多的错误等着你!(所以要整理出这么一份东西来。。。)
=======================================================================================
错误一:安装NS2.34过程中出现如下的错误:
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:
make: *** [tools/ranvar.o]错误1
Ns make failed!
See http://www.isi.edu/nsnam/ns/ns-problems.html for problems
即:将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_);
======================================================================================
错误二:
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’
mac/mac-802_11Ext.h:175:41: error: ‘dh_body’ was not declared in this scope
mac/mac-802_11Ext.h:175:51: error: ‘offsetof’ was not declared in this scope
mac/mac-802_11Ext.h:177:3: warning: control reaches end of non-void function [-Wreturn-type]
make: *** [mac/mac-802_11Ext.o] Error 1
Ns make failed!
下面是网上找得关于本问题的解决方案:
If you get error like:
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
open that file and add
#include <cstddef>
to the header files.
在ns-allinone-2.34\ns-2.34\mac\mac-802_11Ext.h 文件添加#include <cstddef>
然后重新安装,就OK了。
=============================================================================
错误三:
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:
mobile/nakagami.cc:185:67: error: cannot call constructor ‘GammaRandomVariable::GammaRandomVariable’ directly
mobile/nakagami.cc:185:67: error:
make: *** [mobile/nakagami.o]错误1
Ns make failed!
See http://www.isi.edu/nsnam/ns/ns-problems.html for problems
解决方法:
在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();
重新在ns目录下键入$ ./install安装,再次出现同类问题时,仿照此次解决方法,找到对应的文件和行数,修改即可。直到安装成功。
=======================================================================================
在/home目录下
sudo gedit .bashrc 在弹出的窗口文件最后输入 export PATH=$PATH:/home/yourfile/ns-allinone-2.34/bin:/home/yourfile/ns-allinone-2.34/tcl8.4.18/unix:/home/yourfile/ns-allinone-2.34/tk8.4.18/unix
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/yourfile/ns-allinone-2.34/otcl-1.13:/home/yourfile/ns-allinone-2.34/lib
export TCL_LIBRARY=$TCL_LIBRARY:/home/yourfile/ns-alllinone-2.34/tcl8.4.18/library
============================
验证(测试)
(1)打开一个新的终端
(2)输入ns并回车
$ns (如果正常,会出现"%"操作提示符,如果显示还没有安装ns2,可以先安装nam,再测试ns)
(3)输入一段测试用的Tcl脚本代码进行测试
%puts "Hello World" (输出Hello World字符串)
Hello World (如果正确,会显示Hello World)
% (然后跳到下一个"%"提示符等待下一条指令输入)
============================
安装nam
cd ns-allinone-2.34/nam-1.14
./configure
make
sudo make install (至此,nam安装好)
(本人nam安装完成后一直没有办法正确使用,照网上打过补丁之后依旧是老毛病,今天偶然使用这个方法安装竟然就奇迹般的可以使用了,在此表示诚挚的感谢,泪流满面啊!!!)
到此ns2终于安装好!!
如果遇到其他安装过程中的问题还会继续更新本文。
PS: ns2相关学习资料网址
百思论坛
http://www.baisi.net/forum-440-1.html
向ns2中添加新的队列算法
http://www.cs.cmu.edu/~istoica/csfq/step-by-step.html#fred-ref
ns2教学手册
http://hpds.ee.ncku.edu.tw/~smallko/ns2/ns2.htm