ns2 安装与问题集锦

转自: http://hi.baidu.com/_dragonwarrior/blog/item/ba462fdc070fde43ccbf1a9e.html 

 

Ubuntu 10.04 下 安装 NS2.30 

1. NS2下载 

   在OpenSource中search  NS2.30 

   我下载的版本是NS2.30, 下载的文件为ns-allinone-2.30.tar.gz。 

   下载完后将它解压缩到主文件夹下(我的是 /home/Soft/ns2): 

    tar xvfz ns-allinone-2.30.tar.gz 

2. 需要用到的软件包 

  build-essential 

  tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev 

  libxmu-dev 

3. 安装 

   cd/home/nuaa/Soft/ns-allinone-2.30 

   sudo ./install 

4. 出错处理

1). 

ld -shared -olibotcl.so otcl.o 

otcl.o: Infunction `OTclDispatch': 

/home/yanna/ns-allinone-2.30/otcl-1.12/otcl.c:495:undefined reference to `__stack_chk_fail_local' 

otcl.o: Infunction `Otcl_Init': 

/home/yanna/ns-allinone-2.30/otcl-1.12/otcl.c:2284:undefined reference to `__stack_chk_fail_local' 

ld: libotcl.so:hidden symbol `__stack_chk_fail_local' isn't defined 

ld: final linkfailed: Nonrepresentable section on output 

make: ***[libotcl.so] 错误 1cd ns-2.30;./validate 

otcl-1.12 makefailed! Exiting ... 

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

 

在官网上有解决方案,应该是个BUG,会在以后版本中解决:

otcl.o: In function `OTclDispatch': 

/home/ns/ns-allinone-2.30/otcl/otcl.c:495:undefined reference to `__stack_chk_fail_local' 

otcl.o: In function `Otcl_Init': 

/home/ns/ns-allinone-2.30/otcl/otcl.c:2284:undefined reference to `__stack_chk_fail_local' 

ld: libotcl.so: hidden symbol `__stack_chk_fail_local'isn't defined 

ld: final link failed: Nonrepresentablesection on output 

make: *** [libotcl.so] Error 1 

This error is because the linker being usedis "ld -shared" instead of"gcc -shared".  If you edit one line in otcl-1.12/configure,and rerun install , it should work: 

修改   /home/nuaa/Soft/ns2/ns-allinone-2.30/otcl-1.12/configure  文件


;; 

Linux*) 

SHLIB_CFLAGS="-fpic"

SHLIB_LD="ld-shared"   →   SHLIB_LD="gcc-shared" 

SHLIB_SUFFIX=".so"

DL_LIBS="-ldl"

SHLD_FLAGS=""

This will be fixed in future revisions ofns-2.    改完后重新安装。

2). 

Tcl.cc:In member function ‘void Tcl::eval(char*)’:
Tcl.cc:182: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc: In member function ‘int TclObject::traceVar(const char*, TclObject*)’:
Tcl.cc:421: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc: In static member function ‘static int TclClass::create_shadow(void*,Tcl_Interp*, int, const char**)’:
Tcl.cc:509: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc:511: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc: In static member function ‘static int TclClass::dispatch_instvar(void*,Tcl_Interp*, int, const char**)’:
Tcl.cc:566: error: invalid conversion from ‘const char*’ to ‘char*’
Tcl.cc:571: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc: In member function ‘virtual void TclClass::bind()’:
Tcl.cc:603: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc:605: warning: deprecated conversion from string constant to ‘char*’
make: *** [Tcl.o] 
错误 1
tclcl-1.18 make failed! Exiting ...

*******************************************************原作者解决方法开始************************************************************

由于gcc版本过高引起的编译问题 gcc-4.4  --> gcc-4.3

 1. sudo apt-get install gcc-4.3

安装了之后,系统之中就存在两个GCC版本4.44.3,可以通过ls命令查看: 

   1. ls /usr/bin/gcc*   

   2. /usr/bin/gcc  /usr/bin/gcc-4.3  /usr/bin/gcc-4.4  /usr/bin/gccbug-4.3 

但是这时系统默认的GCC还是4.4版的,可以通过gcc -v查看版本号 

设置GCC4.3GCC4.4的可选项,在终端输入以下命令 

   1.  sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 40

   2.  sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 30  

现在设置GCC的默认版本,输入下面命令: 

sudoupdate-alternatives --config gcc 

我得到的结果: 

There are 2choices for the alternative gcc (providing /usr/bin/gcc). 

  Selection   Path              Priority   Status 

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

* 0            /usr/bin/gcc-4.4   40       auto mode 

  1           /usr/bin/gcc-4.3   30        manual mode 

  2           /usr/bin/gcc-4.4   40        manual mode 

然后输入“1”,再查看一下gcc的版本,已经变成4.3的了~~~~ 

同样对于g++也可以使用同样的方法从4.4高版本切换到4.3低版本。。。

*******************************************************原作者解决方法结束************************************************************

*******************************************************我的解决方法开始************************************************************

由于我按照上述步骤装了gcc-4.3的不行,又装了gcc-4.1的仍然不行,于是就干脆进到tclcl-1.18文件夹下查找原因,最终发现的确因为是编译器版本过高引起的,但是是由于g++版本过高,而不是gcc,解决步骤如下:

1. sudo apt-get install g++-4.1

2. ls /usr/bin/g++*

得到结果:

/usr/bin/g++  /usr/bin/g++-4.1  /usr/bin/g++-4.4

3. update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 40

4. update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.1 30

5. sudo update-alternatives --config g++

得到结果:
  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/g++-4.4   40        auto mode
  1            /usr/bin/g++-4.1   30        manual mode
  2            /usr/bin/g++-4.4   40        manual mode
选择1即可

 

5. 配置环境变量 

   安装完成后会看到修改环境变量的提示: 

Please put /home/nuaa/Soft/ns2/ns-allinone-2.30/bin,/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/unix,home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/unix" 

into your PATH environment; so that you'llbe able to run itm/tclsh/wish/xgraph. 

IMPORTANT NOTICES: 

(1) You MUST put /home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/otcl-1.12,/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/lib

   into your LD_LIBRARY_PATH environment variable. 

    Ifit 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/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/libraryinto your TCL_LIBRARY environmental 

   variable. Otherwise ns/nam will complain during startup. 

After these steps, you can now run the nsvalidation suite with 

cd ns-2.30; ./validate 

For trouble shooting, please first read nsproblems page 

http://www.isi.edu/nsnam/ns/ns-problems.html.Also search the ns mailing list archive 

for related posts . 

   回到主文件夹,修改bash配置文件.bashrc: 

  sudo gedit .bashrc 

   在文件最后加上: 

PATH="$PATH:/home/nuaa/Soft/ns2/ns-allinone-2.30/bin:/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/unix:/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/unix"

LD_LIBRARY_PATH="/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/otcl-1.12:/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/lib"

TCL_LIBRARY="$TCL_LIBRARY:/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/library"

还得运行一个命令,为source .bashrc

 

6. 安装验证 

   安装结束后的提示中也告诉我们如何验证是否正确安装: 

   cdns-2.30 

  ./validate 

   另外,也可以打开一个新终端进行试运行: 

   输入ns,如果显示一个%则说明已正确安装。如果提示“command not found”则重新启动试试。


安装NS-2.28全过程一(包括所有可能遇到的问题)

NS2.28在Ubuntu7.10下的安装

安装包是ns-allinone-2.28.tar.gz。Ubuntu7.10内核是2.6.22-14.

首先sudo apt-get update

sudo apt-get install build-essential                        这是更新ubuntu

sudo apt-get install tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev          这是为安装NS做准备

sudo apt-get install libxmu-dev libxmu-headers              安装nam做准备

解压缩后,

输入:cd ns-allinone-2.28
  输入:ls -a 
  回车后就可以看到一个名字为install的文件. 
  然后在终端中输入:./install 
   OK,NS开始安装了
          然后waiting……

出现问题及解决方法

问题1 

checking system version (for dynamic loading)... ./configure: 1: Syntax error: Unterminated quoted string

tcl8.3.2 configuration failed! Exiting ...

Tcl is not part of the ns project. Please see www.Scriptics.com

to see if they have a fix for your platform.

解决方法

分别进入以下目录:
tcl8.x.x/unix/tcl.m4.
tk8.x.x/unix/tcl.m4.  
otcl-1.x/configure.in.
将这些文件里的system=MP-RAS-`awk ' { print $3 } '/tc/.relid'` 改为:
system=MP-RAS-`awk ' { print $3 } '/etc/.relid`  

然后再在这三个目录下运行命令autoconf.每个目录下运行两次~

问题2

继续输入 ./install

./sctp/sctp.h:630: error: extra qualification ‘SctpAgent::’on member ‘DumpSendBuffer’ make: *** [trace/trace.o] Error 1

Ns make failed!

解决办法

将文件sctp.h里面第630行DumpSendBuffer函数前面的'SctpAgent::'去掉。

问题3

继续输入 ./install

./mobile/god.h:88: error: extra qualification ‘vector::’ on member ‘operator=’

./mobile/god.h:93: error: extra qualification ‘vector::’ on member ‘operator+=’

./mobile/god.h:98: error: extra qualification ‘vector::’ on member ‘operator==

./mobile/god.h:101: error: extra qualification ‘vector::’ on member ‘operator!=’

make: *** [src_rtg/sragent.o] Error 1

Ns make failed!

解决办法:
分别将这些文件里面的‘vector::'去掉。

问题 4

queue/cbq.cc:112: error: ISO C++ forbids declaration of ‘CBQueue’ with no type

queue/cbq.cc:112: error: expected ‘;’ before ‘*’ token

queue/cbq.cc: In member function ‘virtual int CBQueue::insert_class(CBQClass*)’:

queue/cbq.cc:488: error: ‘class CBQClass’ has no member named ‘cbq_’

queue/cbq.cc: In constructor ‘CBQClass::CBQClass()’:

queue/cbq.cc:805: error: class ‘CBQClass’ does not have any field named ‘cbq_’

queue/cbq.cc: In member function ‘virtual void CBQClass::recv(Packet*, Handler*)’:

queue/cbq.cc:850: error: ‘cbq_’ was not declared in this scope

queue/cbq.cc:856: error: ‘cbq_’ was not declared in this scope

queue/cbq.cc: In member function ‘void CBQClass::update(Packet*, double)’:

queue/cbq.cc:873: error: ‘cbq_’ was not declared in this scope

queue/cbq.cc: In member function ‘int CBQClass::desc_with_demand()’:

queue/cbq.cc:928: error: ‘cbq_’ was not declared in this scope

queue/cbq.cc: In member function ‘void CBQClass::newallot(double)’:

queue/cbq.cc:975: error: ‘cbq_’ was not declared in this scope

queue/cbq.cc: In member function ‘virtual int CBQClass::command(int, const char* const*)’:

queue/cbq.cc:1002: error: ‘cbq_’ was not declared in this scope

make: *** [queue/cbq.o] Error 1

Ns make failed!

解决办法

用补丁——
补丁的用法即找到相应文件后,找到相应的程序段,行列数为@@ ...... @@之间数字,手动把补丁程序段中前面带有“+”号的行添加到文件中,而将前面带有“-”号的行在文件中删除,这是很花费时间的一件事,要有耐心~~

(网上很多类似的补丁,但很少类似的补丁用法说明。我自己在这里也浪费了很多时间,后来慢慢摸索出来的,为了看明白还去找了些patch的说明来看,后来还是一个同学说的好,patch为后缀的补丁包其实是注明了在哪个文件中的什么地方添加什么程序段,减少什么程序段)

用如下补丁
--- cbq.cc.old 2006-08-31 11:42:09.000000000 -0300
+++ cbq.cc 2006-08-31 11:43:31.000000000 -0300

@@ -87,6 +87,8 @@

#define LEAF_LEVEL 1 /* level# for leaves *
#define POWEROFTWO 16
+class CBQueue;
+
class CBQClass : public Connector {
   public:
   friend class CBQueue;

问题5

./tora/tora_neighbor.h:72: error: ISO C++ forbids declaration of ‘toraAgent’ with no type

./tora/tora_neighbor.h:72: error: expected ‘;’ before ‘*’ token

make: *** [tora/tora.o] Error 1

Ns make failed!

解决办法:
用如下补丁——
--- tora_neighbor.h.old 2006-08-31 11:57:34.000000000 -0300
+++ tora_neighbor.h 2006-08-31 11:58:11.000000000 -0300
@@ -41,6 +41,8 @@

#ifndef __tora_neighbor_h__
#define __tora_neighbor_h__
  +class toraAgent;
  +
   enum LinkStatus {
   LINK_UP = 0x0001, // upstream
   LINK_DN = 0x0002, // downstream

问题6

dsr/dsragent.cc: In member function ‘void DSRAgent::handleFlowForwarding(SRPacket&, int)’:

dsr/dsragent.cc:804: error: ‘XmitFlowFailureCallback’ was not declared in this scope

dsr/dsragent.cc: In member function ‘void DSRAgent::sendOutPacketWithRoute(SRPacket&, bool, Time)’:

dsr/dsragent.cc:1361: error: ‘XmitFailureCallback’ was not declared in this scope

dsr/dsragent.cc:1362: error: ‘XmitFlowFailureCallback’ was not declared in this scope

dsr/dsragent.cc:1379: error: ‘XmitFailureCallback’ was not declared in this scope

make: *** [dsr/dsragent.o] Error 1

Ns make failed!

解决办法

打开       dsr/dsragent.cc 搜索XmitFlowFailureCallback和XmitFailureCallback,发现除了828、1385、1386、1403行之外,在文件后面还有这两个函数声明,把这两个函数声明移到文件前面

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Ubuntu上安装NS2,你可以按照以下步骤进行操作: 1. 打开终端(Ctrl+Alt+T)。 2. 更新软件包列表和系统: ``` sudo apt update sudo apt upgrade ``` 3. 安装NS2的依赖库: ``` sudo apt install build-essential autoconf automake libxmu-dev ``` 4. 下载NS2的源代码包。你可以在NS2的官方网站(https://www.isi.edu/nsnam/ns/)上找到最新的稳定版本。 5. 解压源代码包: ``` tar -xzvf ns-allinone-<version>.tar.gz ``` 其中,`<version>` 是你下载的源代码包的版本号。 6. 进入解压后的目录: ``` cd ns-allinone-<version> ``` 7. 配置NS2安装选项: ``` ./install ``` 这将会运行一个配置脚本,询问一些选项。你可以按照默认值进行安装,或者根据需要进行自定义配置。 8. 编译和安装NS2: ``` make sudo make install ``` 9. 配置环境变量: 打开 `~/.bashrc` 文件,并添加以下行: ``` export PATH=$PATH:/path/to/ns-allinone-<version>/bin:/path/to/ns-allinone-<version>/tcl8.5.10/unix:/path/to/ns-allinone-<version>/otcl-1.14 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/ns-allinone-<version>/otcl-1.14:/path/to/ns-allinone-<version>/lib ``` 替换 `/path/to/ns-allinone-<version>` 为你实际解压的目录路径。 10. 使环境变量生效: ``` source ~/.bashrc ``` 11. 测试安装: 运行以下命令以验证NS2是否成功安装: ``` ns ``` 如果没有报错并成功打开NS2的命令行界面,那么说明安装成功。 希望这些步骤可以帮助你在Ubuntu上安装NS2。如果你遇到任何问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值