总的来说还比较顺利,因为网上已经有很多教程。呼呼~记一下自己遇到的问题和解决方法(多谢前辈们的帖和文啦)。
1、首先下载ns-allinone-2.33.tar.gz。这个去官网上找就可以了,Google一下也有很多吧。
2、按照[1]的步骤,先更新了一下系统。在终端输入:
sudo apt-get update
#更新源列表
sudo apt-get upgrade
#更新已安装的包
sudo apt-get dist-upgrade
#更新软件,升级系统
3、装几个需要使用的软件包
sudo apt-get remove gcc
#移除gcc
sudo apt-get install build-essential
#for gcc and
some essential
sudo apt-get install tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev
#for tcl and tk
sudo apt-get install libxmu-dev libxmu-headers
#for
nam
4、安装NS2
sudo tar -xzf ns-allinone-2.33.tar.gz
#解压到当前目录/home/kevin/ns2/
cd ns-allinone-2.33
#进入目录
sudo
./install
#开始安装
然后命令行快速刷新,确实很养眼。但不一会突然报错:
……(以上省略)
make: *** [libotcl.so] 错误 1
otcl-1.13 make
failed! Exiting ...
See
http://www.isi.edu/nsnam/ns/ns-problems.html for problems
卡住了,很郁闷,于是上网找解决方法。在[2]上得到结果如下:
gcc 4.0版本以前是用ld -share来生成共享库的,但是到了4.0以上的版本,这个命令改为了gcc -share。在终端里输入gcc -v查看,我的版本是gcc version 4.4.3。
开始修改。
cd
/home/kevin/ns2
/ns-allinone-2.33/otcl-1.13
sudo gedit configure.in
把77行的SHLIB_LD="ld -shared",改为SHLIB_LD="gcc -shared",保存退出。然后
sudo gedit configure
按照[2]中的说法,在5518行, 把SHLIB_LD="ld -shared"改为SHLIB_LD="gcc -shared",保存退出。
cd回到目录ns-allinone-2.33下,重新运行
sudo ./install
顺利完成安装。最后出来提示:
Please put /home/kevin/ns2/ns-allinone-2.33/bin:/home/kevin/ns2/ns-allinone-2.33/tcl8.4.18/unix:/home/kevin/ns2/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/kevin/ns2/ns-allinone-2.33/otcl-1.13, /home/kevin/ns2/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/kevin/ns2/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.
5、配置环境变量
用cd进入目录/home /kevin ( kevin 是我的用户名),然后
sudo gedit .bashrc
在文件末尾加入:
PATH="$PATH: /home/kevin/ns2 /ns-allinone-2.33/bin: /home/kevin/ns2 /ns-allinone-2.33/tcl8.4.18/unix: /home/kevin/ns2 /ns-allinone-2.33/tk8.4.18/unix"
LD_LIBRARY_PATH=" /home/kevin/ns2 /ns-allinone-2.33/otcl-1.13: /home/kevin/ns2 /ns-allinone-2.33/lib"
TCL_LIBRARY="$TCL_LIBRARY: /home/kevin/ns2 /ns-allinone-2.33/tcl8.4.18/library"
保存退出(上述内容在安装结束后的提示中有,见粗体部分)。
6、验证
打开一个新终端,输入ns,如果出现%,则说明安装成功。
也可以进入 /home/kevin/ns2 /ns- allinone-2.33/ns-2.33/,输入./validate验证。
到此。上面红色标注的部分记得都要用自己的安装路径替换。
参考:
http://merofxin.blogbus.com/logs/54669787.html