您的位置:首页 > 其它

ubuntu下ns2-allinone-2.34…

2014-01-14 20:14 295 查看
原文地址:ubuntu下ns2-allinone-2.34安装方法【呕心沥血整理版】作者:寒枫傲天最近一直在使用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: 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 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.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 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.34ns-2.34macmac-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: 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.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命令,弹出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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: