转自:http://blog.163.com/zhuandi_h/blog/static/18027028820125742050658/
系统:win7,winXp
cygwin安装教程:
1.下载NS2.33
http://sourceforge.net/projects/nsnam/files/allinone/
或http://download.youkuaiyun.com/download/morre/1114655
2.解压
将ns-allinone-2.33.tar.gz拷贝至cygwin下home目录下的个人用户中,如我的cygwin/home/lenovo
启动cygwin,输入以下命令,实现解压
tar zxvf ns-allinone-2.33.tar.gz
3.修改源代码
源码中存在一些错误,需要进行修改在编译
在C:\cygwin\home\lenovo\ns-allinone-2.33\tcl8.4.18\unix中增加如下定义,添加如下:
#include "tclInt.h"
#include "tclPort.h" #include <locale.h> #define TM_YEAR_BASE 1900 #define IsLeapYear(x) ((x % 4 == 0) && (x % 100 != 0 || x % 400 == 0))
/* * TclpGetDate is coded to return a pointer to a 'struct tm'. For * thread safety, this structure must be in thread-specific data. * The 'tmKey' variable is the key to this buffer. */
static Tcl_ThreadDataKey tmKey; typedef struct ThreadSpecificData { struct tm gmtime_buf; struct tm localtime_buf; } ThreadSpecificData;
/*
*增加如下定义
*/
struct timezone{ int tz_minuteswest; int tz_dsttime; };
/* * If we fall back on the thread-unsafe versions of gmtime and localtime, * use this mutex to try to protect them. */
如不进行修改,则可能会出现以下错误:
/home/lenovo/ns-allinone-2.33/tcl8.4.18/unix/tclUnixTime.c
/home/lenovo/ns-allinone-2.33/tcl8.4.18/unix/tclUnixTime.c: In function `TclpGetClicks':
/home/lenovo/ns-allinone-2.33/tcl8.4.18/unix/tclUnixTime.c:100: error: storage size of 'tz' isn't known
/home/lenovo/ns-allinone-2.33/tcl8.4.18/unix/tclUnixTime.c:100: warning: unused variable `tz'
/home/lenovo/ns-allinone-2.33/tcl8.4.18/unix/tclUnixTime.c: In function `Tcl_GetTime':
/home/lenovo/ns-allinone-2.33/tcl8.4.18/unix/tclUnixTime.c:253: error: storage size of 'tz' isn't known
/home/lenovo/ns-allinone-2.33/tcl8.4.18/unix/tclUnixTime.c:253: warning: unused variable `tz'
Makefile:1089: recipe for target `tclUnixTime.o' failed
make: *** [tclUnixTime.o] Error 1
4.打补丁
http://bugs.gentoo.org/show_bug.cgi?id=225999下载补丁tk-8.4.18-tkBind.patch(右键单击tk-8.4.18-tkbind.patch 然后保存在allinone-2.33目录下)
进入allinone-2.33目录打上补丁,输入以下命令打补丁:
cd /home/lenovo/allinone-2.33
patch -p0 < tk-8.4.18-tkBind.patch
5.安装
进入allinone-2.33目录,进行安装
./install
编译较漫长。
成功后出现以下界面
6.配置环境变量
打开cygwin\home\lenovo\.bashrc文件,在文件末尾加入这些信息:
export NS_HOME=/home/lenovo/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
注:.bashrc文件可以用记事本打开,不过最好用UE,因为它是unix格式的文本
7.测试NS2
关闭cygwin,打开Xwin Server,输入以下命令:
$ /home/lenovo/ns-allinone-2.33/ns-2.33/tcl/ex
$ ns simple.tcl
则会出现以下模拟图,点击运行按钮,可观看网络流量的流动:
至此,NS2.31安装成功。
170

被折叠的 条评论
为什么被折叠?



