ns-2安装错误二

原文:http://blog.csdn.net/xdruan/article/details/6588162

ns2可在官方网站下载,我下的是all in one的压缩包:ns-allinone-2.34.tar.gz。

All in one这类压缩包实际上是傻瓜安装包,只要解压,然后执行./install即可完成安装。

不过出了点编译错误,经过网上的参考,要做以下几步。

1. 更新软件包:

ubuntu 11.04的gcc版本为4.5,而ns2.34只能在gcc 4.4及以下版本安装

(1) 安装gcc-4.4
输入:sudo apt-get intall gcc-4.4
(2) 安装g++-4.4
输入:sudo apt-get intall g++-4.4

(3) 安装

$ 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-head

 

2. 对于Ubuntu 11.04版,要修改两个配置文件:

cd /opt/ns-allinone-2.34/otcl-1.13
sudo gedit configure.in
把 第77行的
SHLIB_LD="ld -shared"
修改成
SHLIB_LD="gcc -shared
存档退出

sudo gedit configure
把 第5518行附近
SHLIB_LD="ld -shared"
修 改成
SHLIB_LD="gcc -shared"

 

3. 遇到的错误

(1) 错误一:安装NS2.33过程中出现如下的错误:

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

这是由于gcc版本提高后对类内部函数调用的简化造成的不兼容,解决方法如下:

在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_);

(2) 错误二:重新在ns目录下键入$ ./install安装,再次出现同类问题时,

如:

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’

make: *** [mobile/nakagami.o]错误1

Ns make failed!

See http://www.isi.edu/nsnam/ns/ns-problems.html for problems

解决方法:

在ns-allinone-2.33/ ns-2.33/ mobile文件夹下,找到报错提示中的nakagami.cc文件,打开找到对应的183行删除::ErlangRandomVariable,保存,

即:将183行的

resultPower = ErlangRandomVariable::ErlangRandomVariable(Pr/m, int_m).value();

改为:

resultPower = ErlangRandomVariable(Pr/m, int_m).value();

在ns-allinone-2.33/ ns-2.33/ mobile文件夹下,找到报错提示中的nakagami.cc文件,打开找到对应的185行删除::GammaRandomVariable,保存,

即:将185行的

resultPower = GammaRandomVariable::GammaRandomVariable(m, Pr/m).value();

改为:

resultPower = GammaRandomVariable(m, Pr/m).value();

重新在ns目录下键入$ ./install安装,再次出现同类问题时,仿照此次解决方法,找到对应的文件和行数,修改即可。直到安装成功。

(3) 错误三:*** buffer overflow detected ***: ns terminated

修改tcl8.4.18/unix文件夹下的文件Makefile.in
将Makefile.in的270行:
CC = @CC@
修改为:
CC = @CC@ -V 4.4
注意是大写的‘V’,这样gcc使用的参数版本为4.4。

4. 执行./install

安装成功提示:

-----------------------------------------------------------------------------------------------------------------------------------------

IMPORTANT NOTICES:

(1) You MUST put /home/ruan/ns-allinone-2.34/otcl-1.13, /home/ruan/ns-allinone-2.34/lib, 
    into your LD_LIBRARY_PATH environment variable.
    If it complains about X libraries, add path to your X libraries 
    into LD_LIBRARY_PATH.
    If you are using csh, you can set it like:
setenv LD_LIBRARY_PATH <paths>
    If you are using sh, you can set it like:
export LD_LIBRARY_PATH=<paths>

(2) You MUST put /home/ruan/ns-allinone-2.34/tcl8.4.18/library into your TCL_LIBRARY environmental
    variable. Otherwise ns/nam will complain during startup.

After these steps, you can now run the ns validation suite with
cd ns-2.34; ./validate

For trouble shooting, please first read ns problems page 
http://www.isi.edu/nsnam/ns/ns-problems.html. Also search the ns mailing list archive
for related posts.
-----------------------------------------------------------------------------------------------------------------------------------------

 

5. 设置环境变量

到/etc/profile下面增加:

PATH="$PATH:%/ns-allinone-2.34/bin:%/ns-allinone-2.34/tcl8.4.18/unix:%/ns-allinone-2.34/tk8.4.18/unix"
LD_LIBRARY_PATH="%/ns-allinone-2.34/otcl-1.13:%/ns-allinone-2.34/lib" 
TCL_LIBRARY="$TCL_LIBRARY:%/ns-allinone-2.34/tcl8.4.18/library" 

%改成你ns2文件存放的位置,然后执行source /etc/profile

网上说还要执行./validate,不过我这里没有validate文件,因此无法执行,但并不影响。

 

6. 安装成功。执行ns,出现%提示符,执行nam,富有个性的图形界面就出来了。

posted @ 2012-09-24 11:14  xiaolongxia  阅读(562)  评论(0)    收藏  举报