NS2各个版本的安装其实都大同小异,但每个升级版本并不向下兼容,所以会考虑到实际需要而安装多个NS2版本,将在后续文章中说明本人安装多个NS2版本的关键点,本文主要就在WinXP SP2下安装NS2.33的主要过程和相关疑问解答罗列出来,具体可参见文章最后列出的参考网址,如有疑问,欢迎联系本人。

Step1
        在http://www.cygwin.com/上下载“Cygwin”(setup.exe)。在select packages界面,保持缺省的同时,下载以下相应的选项 ,下载完毕后安装,即可。
     gawk、gcc、 gcc-g++、gnuplot、make、patch、perl、tar、X-startup-scripts、xorg-x11-base、 xorg-x11-bin、xorg-x11-devel、xorg-x11-bin-dlls、xorg-x11-bin-lndir、xorg- x11-etc、xorg-x11-fenc、xorg-x11-fnts、xorg-x11-libs-data、xorg-x11-xwin、 libxt-devel、libXmu-devel。


Step2

        在http://www.isi.edu/nsnam/dist/上下载ns-allinone-2.33.tar.gz
,存放在自己的目录c:/cwgwin/home/jerry下。在该目录下使用tar xvfz ns-allinone-2.33.tar.gz命令解压。解压后回生成目录ns-allinone-2.33。在该目录下使用./install命令安装ns2

Step3

        修改环境变量。将
export NS_HOME=/home/jerry.wu/ns-allinone-2.33

export PATH=$NS_HOME/tcl8.4.18/unix:$NS_HOME/tk8.4.18/unix:$NS_HOME/bin:$PATH

export LD_LIBRARY_PATH=$NS_HOME/tcl8.4.18/unix:$NS_HOME/tk8.4.18/unix:$NS_HOME/otcl-1.13:$NS_HOME/lib:$LD_LIBRARY_PATH

export TCL_LIBRARY=$NS_HOME/tcl8.4.18/library

拷贝到c:/cwgwin/home/ Administrator
的文件.bashrc中,即可成功设置环境变量。

Step4

       检验ns和nam命令。输入startxwin.sh命令,在出现的视图窗口下进入jerry.wu\ns-allinone- 2.33\ns-2.33\tcl\ex\wpan
,在该目录下运行ns wpan_demo3.tcl,对运行结果进行观察。
       至此,Cygwin+ns-allinone-2.33
安装成功!


Problems & Solutions


P:   运行 startxwin.bat 时提示”No Such File or Directory”

S:   可能是没有安装X-Startup-Scripts,重新运行setup.exe,然后选择安装就行了

P:   运行 ns examples2.tcl 时提示” no such file or directory”

S:   如果是找不到 examples2.tcl 那就是你打 cd /home/hct/ns-allinone-2.28/ns-2.28/ns-tutorial/examples 的时候出了错 ,如果是找不到ns,那就是环境变量没设置好

P:   运行 ns examples2.tcl 时提示”nam:   no such file or directory”

S:   看看你的 /home/hct/ns-allinone-2.28/nam-1.11 目录下有没有 nam.exe 文件,有的话就是你的环境变量设置错了,注意要把 nam-1.11 这个目录加到PATH中
     如果没有nam.exe,那就是编译nam时出错了。运行 gcc -dumpversion 看看你的gcc版本,如果是3.4.x,那就好办了。找到 nam-1.11/agent.h ,把它的第73行中的NULL改成0,然后回到nam-1.11目录,运行 ./configure 然后运行 make,等运行完毕,再试试 ns example2.tcl 就应该没问题了
     如果gcc版本不是3.4.x,那就不知道是什么问题了,不过可以肯定是编译出了错,所以换个nam版本试试吧

P:   编译nam的时候出现错误:can’t find X includes

S:   未安装libXt-devel,用cygwin的setup升级安装这个组件

P:   编译nam时出现错误:缺少WinUtil.h

S:   未安装libXmu-devel,用cygwein的setup升级安装这个组件

P:   编译nam时出现错误:invalid user “bin”

S:   修改makefile.in和makefile.vc,搜错/user/bin/install -c -m -o bin -g bin,并将其改为/user/bin/install -c -m -o [your user name]

P:   在执行ns example2.tcl之后显示错误:nam [code omitted because of length]

S:    这个是由于nam调用的tk组件和xproto-7.0.13不兼容导致的(xproto-7.0.13 新添加了 GenericEvent)。
到这里下载补丁http://bugs.gentoo.org/show_bug.cgi?id=225999
tk-8.4-lastevent.patch。然后打补丁,补丁之后重新编译ns,这时可能会需要将原始的包ns-allinone-2.28中 tck8.4.5\unix\dltest\里面的文件复制到cygwin\home\RoronoaZaoxl\ns-allinone-2.28 \tcl8.4.5\unix\dltest下面才能重新编译。

具体的指令如下:
[badar@linux ~]$ cd ns-allinone-2.33/tk8.4.18/
[badar@linux tk8.4.18]$ ls
bitmaps compat library macosx tk-8.4.18-tkBind.patch win
ChangeLog doc license.terms README tk-8.4-lastevent.patch xlib
changes generic mac tests unix
[badar@linux tk8.4.18]$ patch -p1 < ./tk-8.4-lastevent.patch
can’t find file to patch at input line 3
Perhaps you used the wrong -p or –strip option?
The text leading up to this was:
————————–
|— generic/tk.h.orig 2008-02-06 16:31:40.000000000 +0100
|+++ generic/tk.h 2008-07-24 08:21:46.000000000 +0200
————————–
File to patch: generic/tk.h
patching file generic/tk.h
[badar@linux tk8.4.18]$ cd ..
[badar@linux ns-allinone-2.33]$ ./install
  

References:
http://x.cygwin.com/docs/ug/setup-cygwin-x-installing.html
http://140.116.72.80/~smallko/ns2/setup.htm
http://forums.fedoraforum.org/showthread.php?t=206795
http://bbs.cnttr.com/viewthread.php?tid=190413&page=1&authorid=319430
http://blog.sina.com.cn/s/blog_4a5f138701000bbv.html
http://perti.blog.sohu.com/47330681.html
http://user.qzone.qq.com/14926710/blog/1199810570
http://user.qzone.qq.com/187375679/blog/1234963865
posted on 2009-09-26 10:43  Berkeley  阅读(1075)  评论(0编辑  收藏  举报