ns2安装过程相关问题

来源:互联网 发布:器乐培训行业数据 编辑:程序博客网 时间:2024/05/29 10:02
最近一直在使用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。
修改命令如下:
cd ns-allinone-2.34/otcl-1.13
  
  sudo gedit configure.in

  把77行处的
  SHLIB_LD="ld-shared"
  改为
  SHLIB_LD="gcc-shared"
  保存退出,然后
  
  sudo gedit configure
  把6304行(Ctrl+i跳到6304行)的
  SHLIB_LD="ld-shared"
  改为
  SHLIB_LD="gcc-shared"
  保存退出,然后
  cdns-allinone-2.34 #到安装目录
  sudo./install #开始安装

如果没有更改直接安装,就会出现这样的错误:
ld: 
libotcl.so: hidden symbol `__stack_chk_fail_local' isn't defined
ld: final link failed: Bad value
make: *** [libotcl.so] Error 1
这只是有可能出现的第一个错误,接下来还有更多的错误等着你!(所以要整理出这么一份东西来。。。)
=======================================================================================
错误一:安装NS2.34过程中出现如下的错误:
tools/ranvar.cc: In member function ‘virtual doubleGammaRandomVariable::value()’:
tools/ranvar.cc:219:70: error: cannot call constructor‘GammaRandomVariable::GammaRandomVariable’ directly
tools/ranvar.cc:219:70:error:  for a function-stylecast, 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.34/ns-2.34/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_);

 然后保存退出,重新安装ns2.

======================================================================================

错误二

In fileincluded 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: expectedprimary-expression before ‘struct’

mac/mac-802_11Ext.h:175:41: error: ‘dh_body’ wasnot declared in this scope

mac/mac-802_11Ext.h:175:51: error: ‘offsetof’ wasnot declared in this scope

mac/mac-802_11Ext.h:177:3: warning: controlreaches end of non-void function [-Wreturn-type]

make: ***[mac/mac-802_11Ext.o] Error 1


Ns makefailed!

下面是网上找得关于本问题的解决方案:

If you get error like:

mac/mac-802_11Ext.h: In member function ‘u_int32_tPHY_MIBExt::getHdrLen11()’:
mac/mac-802_11Ext.h:176:19: error: expected primary-expressionbefore ‘struct’
mac/mac-802_11Ext.h:176:41: error: ‘dh_body’ was not declared inthis scope
mac/mac-802_11Ext.h:176:51: error: ‘offsetof’ was not declared inthis 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 doubleNakagami::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-stylecast, 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-stylecast, remove the redundant ‘::GammaRandomVariable’

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

Ns make failed!

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

解决方法:

在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安装,再次出现同类问题时,仿照此次解决方法,找到对应的文件和行数,修改即可。直到安装成功。

=======================================================================================

错误

make:***[linkstate/ls.o]

解决方法:
修改ls文件:ns-2.35/linkstate/ls.h  第137行void eraseAll() { erase(baseMap::begin(), baseMap::end()); }改为:void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }然后重新 ./install

=======================================================================================

到这里安装终于成功了,不要忘记添加环境变量
在/home目录下
sudo gedit .bashrc在弹出的窗口文件最后输入exportPATH=$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

exportTCL_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命令,弹出nam界面则说明nam安装好了
0 0