首先声明,本文《Ubuntu 9.10+NS2 2.33+附加gnuplot和gawk 安装》非完全原创,通过收集一些网上资料,根据自己的实际操作体会进行的修改
1、首先是下载ns-allinone-2.33.tar.gz,地址为
下载在ISI官方即可很快的下载(针对教育网用户)
jacob为我的用户名,注意修改
cd /home/jacob
tar xvfz ns-allinone-2.33.tar.gz
2、安装几个需要使用的软件包:
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
3、然后可以进行安装:
cd /home/yyang/ns-allinone-2.33.tar.gz
sudo ./install
然后看到命令行非常养眼地快速翻滚。在结束时突然报错:
ld -shared -o libotcl.so otcl.o
otcl.o: In function `OTclDispatch’:
/home/yyang/ns-allinone-2.33/otcl-1.13/otcl.c:495: undefined reference to `__stack_chk_fail_local’
otcl.o: In function `Otcl_Init’:
/home/yyang/ns-allinone-2.33/otcl-1.13/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: Nonrepresentable section on output
make: *** [libotcl.so] 错误 1
otcl-1.13 make failed! Exiting …
See http://www.isi.edu/nsnam/ns/ns-problems.html for problems
很奇怪的错误,于是上网找解决措施,在http://www.linuxidc.com/Linux/2010-03/25105.htm
发现解决办法:
gcc 4.0版本以前是用ld -share来生成共享库的,但是到了4.0以上的版本(我的为gcc version 4.4.1),这个命令改为了gcc -share即可
解决过程:
cd /home/yyang/ns-allinone-2.33/otcl-1.13
sudo gedit configure.in
把77行处的
SHLIB_LD=”ld -shared”
改为
SHLIB_LD=”gcc -shared”
保存退出,然后
sudo gedit configure
把5518行的
SHLIB_LD=”ld -shared”
改为
SHLIB_LD=”gcc -shared”
保存退出,然后
cd ..
回到目录ns-allinone-2.33下运行
sudo ./install
如果正确安装可以看到提示:
—————————————-
Please put /home/yyang/ns-allinone-2.33/bin:/home/yyang/ns-allinone-2.33/tcl8.4.18/unix:/home/yyang/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/yyang/ns-allinone-2.33/otcl-1.13, /home/yyang/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/yyang/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.
4、设置环境变量和善后工作:
运行命令
cd ..
回到目录 /home/yyang
然后运行
sudo gedit .bashrc
在文件的末尾输入
PATH=”$PATH:/home/yyang/ns-allinone-2.33/bin:/home/yyang/ns-allinone-2.33/tcl8.4.18/unix:/home/yyang/ns-allinone-2.33/tk8.4.18/unix”
LD_LIBRARY_PATH=”/home/yyang/ns-allinone-2.33/otcl-1.13:/home/yyang/ns-allinone-2.33/lib”
TCL_LIBRARY=”$TCL_LIBRARY:/home/yyang/ns-allinone-2.33/tcl8.4.18/library”
然后保存退出(其实这个配置过程,安装结束后的提示中就有)
另外的一种方法,避免重复输入自己的目录
export NS_HOME=/home/jacob/ns-allinone-2.33
export PATH=$NS_HOME/nam-1.13:$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
5、试运行
打开一个新终端,输入ns命令,倘若出现%,则说明安装成功。
另外,可以进入目录/home/yyang/ns-allinone-2.33/ns-2.33
cd /home/yyang/ns-allinone-2.33/ns-2.33
然后运行
./validate
6.GNUPLOT和AWK
sudo apt-get install gawk (for gawk)
sudo apt-get install gnuplot (for gnuplot)
7.关于Xgraph
如果出现Xgraph不能用,那么看一下xgraph12.1文件夹下有无xgraph.exe,如果没有,下载压缩包,解压之后运行
make
make install
8.nam不能用
多是由于环境变量没有设置好
希望NS2的初学者都能有一个快速进步的过程