本来打算在Windows7下安装cygwin,搭建类unix环境来运行ns2运行,cygwin安装顺利,已能看熟悉的$,看到ls,pwd,cp,rm在微软的cmd中飘荡,心中狂喜。但是ns的安装却不顺利,况且cygwin的运行出现了一次次不确定性,缓冲区不足,环境变量出问题。有时,仅一个tar命令,要运行多遍才能成功,间歇性故障总是伴随着大型系统的不稳定性发生(谁叫我导师是搞容错的,哎。。)。于是决定,回到Linux,发挥双系统的优势!
来到Ubuntu 9.10,马上着手进行ns2,安装:
1、首先是下载ns-allinone-2.33.tar.gz,地址为
http://cdnetworks-kr-2.dl.sourceforge.net/project/nsnam/allinone/ns-allinone-2.33/ns-allinone-2.33.tar.gz
下载完毕后,将其放在/home/yyang目录下,注意yyang为我的用户名,解压缩以待后面使用:
cd /home/yyang
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/2009-12/23655p4.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.
运行命令
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”
然后保存退出(其实这个配置过程,安装结束后的提示中就有)
5、试运行
打开一个新终端,输入ns命令,倘若出现%,则说明安装成功。
另外,可以进入目录/home/yyang/ns-allinone-2.33/ns-2.33
cd /home/yyang/ns-allinone-2.33/ns-2.33
然后运行
./validate
Ubuntu 9.10 安装NS2-2.33中ld: final link failed: Nonrepresentable section on output错误的处理
在最近的一次NS2-2.33安装过程中,出现了点问题,就是说一开始在Ubuntu 9.04下安装,顺利结束,后来升级部分软件(我使用的免费光盘安装的Ubuntu)后,重新安装NS2竟然不能编译了。老是出现类似问题:
/home/gang/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 definedld: final link failed: Nonrepresentable section on outputmake: *** [libotcl.so] 错误 1otcl-1.13 make failed! Exiting …这个问题出现得很郁闷,想了好久也没头绪。终于在一篇NsNam bug报告中,发现问题所在。原来是ld的问题,在gcc 4.0版本以前是用ld -share来生成共享库,但是到了4.0以及以上版本,这个命令改为了gcc -share。好了,问题找到了,就知道该怎么处理了。
进入otcl-1.13目录,找到configure.in.因为我用的是ubuntu,所以只改Linux平台部分就得,
将77行,
SHLIB_LD=”ld -shared”
改为
SHLIB_LD=”gcc -shared”
同时修改configure 第5518行
SHLIB_LD=”ld -shared”
改为
SHLIB_LD=”gcc -shared”
重新./install
好了,没有问题了。
set ns [new Simulator]
set tracef [open example1.tr w]
$ns trace-all $tracef
set namtf [open example1.nam w]
$ns namtrace-all $namtf
proc finish {} {
global ns tracef namtf
$ns flush-trace
close $tracef
close $namtf
exec nam example1.nam &
exit 0
}
set n0 [$ns node]
set n1 [$ns node]
$ns duplex-link $n0 $n1 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n0 $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n1 $null0
$ns connect $udp0 $null0
$ns at 0.5 “$cbr0 start”
$ns at 4.5 “$cbr0 stop”
$ns at 5.0 “finish”
$ns run输入下面命令运行:
ns example1.tcl
报错为:
yyang@Lakewalker:~/ns$ nam:
[code omitted because of length]
: no event type or button # or keysym
while executing
“bind Listbox <MouseWheel> {
%W yview scroll [expr {- (%D / 120) * 4}] units
}”
invoked from within
“if {[tk windowingsystem] eq “classic” || [tk windowingsystem] eq “aqua”} {
bind Listbox <MouseWheel> {
%W yview scroll [expr {- (%D)}] units
}
bind Li…”
上网查找解决办法,发现两个网站:
http://purpleroom.blog.sohu.com/131654783.html
http://bugs.gentoo.org/show_bug.cgi?id=225999
在它们的帮助,成功解决问题!
报错的原因在于ns2.33中,nam调用的tk组件和xproto-7.0.13不兼容,因此要打补丁,解决步骤如下:
1、新建一个文档,名为“tk-8.4-lastevent.path”,并将以下内容复制到其中:
— generic/tk.h.orig 2008-02-06 16:31:40.000000000 +0100
+++ generic/tk.h 2008-07-24 08:21:46.000000000 +0200
@@ -635,17 +635,15 @@
*
*—————————————————————————
*/
-#define VirtualEvent (LASTEvent)
-#define ActivateNotify (LASTEvent + 1)
-#define DeactivateNotify (LASTEvent + 2)
-#define MouseWheelEvent (LASTEvent + 3)
-#define TK_LASTEVENT (LASTEvent + 4)
+#define VirtualEvent (MappingNotify + 1)
+#define ActivateNotify (MappingNotify + 2)
+#define DeactivateNotify (MappingNotify + 3)
+#define MouseWheelEvent (MappingNotify + 4)
+#define TK_LASTEVENT (MappingNotify + 5)
#define MouseWheelMask (1L << 28)
–
#define ActivateMask (1L << 29)
#define VirtualEventMask (1L << 30)
-#define TK_LASTEVENT (LASTEvent + 4)
COLORMAP,
0,
0,
+#ifdef GenericEvent
+ 0,
+#endif
VIRTUAL,
ACTIVATE,
ACTIVATE,
保存后,将tk-8.4.18-tkBind.patch置于ns-allinone-2.33下,即进行如下操作:
cd /home/yyang
sudo cp tk-8.4.18-tkBind.patch /home/yyang/ns-allinone-2.33
cd /home/yyang/ns-allinone-2.33
patch -p0 <tk-8.4.18-tkBind.patch
最后,重新安装
cd /home/yyang/ns-allinone-2.33
sudo ./install