Linux下安装NS2.33(建议fedora8)
NS2可以在很多linux系统下安装,不过安装过程比较折腾,支持包很多要匹配,这里介绍下我配置成功的版本。
操作系统建议是fedora8,其他的操作系统也可以就是,最好不要太新版本的,我也在ubuntu10.10上面配过,ubuntu10.10最好装server版本,都装完最好,否则可能会出现问题,过程还是特别折腾的
这里按照fedora8来配置,ubuntu需要配置gcc4.1和g++4.1的,参考下我前篇写的怎么降级装g++4.1的http://blog.csdn.net/fzxy002763/article/details/7687902
首先下载安装NS2.33的http://download.csdn.net/detail/fzxy002763/4389198
PS:有个我基本配置好的版本,由于上传空间限制,分了两个包http://download.csdn.net/detail/fzxy002763/4389249,http://download.csdn.net/detail/fzxy002763/4389305
进入ns-allinone-2.33目录
[xfx@localhost share]$ cd ns-allinone-2.33/
一般是直接install就行了,如果不行的话就要慢慢排错了(最好下载我配置好的,tcl-debug也包含进去了,要不然还要打patch,麻烦点)
PS:很多情况下会在后期出现nam调用不起来的问题,问题原因有点折腾,没有bind上。。。具体也不用管,打两个patch就行,fedora可以直接patch,ubuntu要apt-get下
patch到这https://bugs.gentoo.org/show_bug.cgi?id=225999下载,tk-8.4.18-tkBind.patch (414 bytes, patch) ,tk-8.4-lastevent.patch (843 bytes, text/plain),这两个,建议直接下载,有人文本复制过来的虽然也行,不过有的复制过去包含网页的格式之类的,折腾,还是直接下载好点,要不然可能会报684之类的错误
下载tk-8.4-lastevent.patch放到ns-allinone-2.33/tk8.4.18/里面
然后patch –p1<tk-8.4-lastevent.patch,提示输入时候输入generic/tk.h
接着把tk-8.4.18-tkBind.patch放到ns-allinone-2.33/,然后patch -p0 <tk-8.4.18-tkBind.patch,这个不会提示输入
NS2.33版本这样打就行了,ns2.30我没打成功,tk-8.4.13那个还要修改patch的内容,麻烦很多,所以用2.30的话不如换到2.33吧,除非对编译比较熟的可以去自己改下
打完patch后
[xfx@localhost ns-allinone-2.33]$ ./install
PS:这里如果出现这样的错
ld: libotcl.so: hidden symbol `__stack_chk_fail_local' isn't defined
ld: final link failed: Nonrepresentable section on output
make: *** [libotcl.so] 错误 1
otcl-1.13 make failed! Exiting ...
解决办法如下:
gcc 4.0版本以前是用ld -share来生成共享库的,但是到了4.0以上的版本(我的为gcc version 4.4.1),这个命令改为了gcc -share即可。
cd ns-allinone-2.33/otcl-1.13
gedit configure.in
把77行处的
SHLIB_LD="ld -shared"
改为
SHLIB_LD="gcc -shared"
保存退出
然后
gedit configure
把5518行的
SHLIB_LD="ld -shared"
改为
SHLIB_LD="gcc -shared"
保存退出,
然后
cd ..
回到目录ns-allinone-2.33下运行./install,如果install正确了,那么就会出现
Please put /home/share/ns-allinone-2.33/bin:/home/share/ns-allinone-2.33/tcl8.4.18/unix:/home/share/ns-allinone-2.33/tk8.4.18/unix
into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.
IMPORTANT NOTICES:
(1) You MUST put /home/share/ns-allinone-2.33/otcl-1.13, /home/share/ns-allinone-2.33/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/share/ns-allinone-2.33/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.33; ./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.
这么一长串的东西,这段话是提示你怎么修改path等环境变量的,觉得麻烦的或者对linux不大熟的建议
在/home下面建立一个文件夹share
就是mkdir /home/share,然后把ns-allinone-2.33都放进去,然后path直接用以下设置,在/home下修改.bashrc(ps:这个改的安全点,etc下面的也行,不过改多了会乱)
改这个vi /home/xfx/.bashrc
在末尾添加如下,保存就行了
# NS 2.33 config
export PATH="$PATH:/home/share/ns-allinone-2.33/bin:/home/share/ns-allinone-2.33/tcl8.4.18/unix:/home/share/ns-allinone-2.33/tk8.4.18/unix"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/share/ns-allinone-2.33/otcl-1.13:/home/share/ns-allinone-2.33/lib"
export TCL_LIBRARY="$TCL_LIBRARY:/home/share/ns-allinone-2.33/tcl8.4.18/library"
不是这个目录的可以对应下面,应该能明白怎么修改的吧
Please put /home/share/ns-allinone-2.33/bin:/home/share/ns-allinone-2.33/tcl8.4.18/unix:/home/share/ns-allinone-2.33/tk8.4.18/unix
into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.
对应修改Path
You MUST put /home/share/ns-allinone-2.33/otcl-1.13, /home/share/ns-allinone-2.33/lib,
into your LD_LIBRARY_PATH environment variable.
对应修改LD_LIBRARY
You MUST put /home/share/ns-allinone-2.33/tcl8.4.18/library into your TCL_LIBRARY environmental
variable. Otherwise ns/nam will complain during startup.
对应修改TCL_LIBRARY
现在可以大致测试下了,ns-allinone-2.33/ns-2.33目录下运行
[root@localhost ns-2.33]# ./validate
不会出现could not found就是ok了
然后测试nam,
[root@localhost ns-2.33]# nam
会出现个图形的框子就是可以的了,这样ns2就基本配置好了