之前在cygwin上安装过NS2.28,方法如我的另一篇博客http://blog.youkuaiyun.com/yyx724916/article/details/8613527。后来在使用的过程中又分别安装过NS2.30和NS2.34的版本。NS2.30安装方法和NS2.28相同;NS2.34的安装与前两种有所不同,因此在这儿介绍一下我安装成功的方法。
cygwin的安装和前面讲的安装方法相同:http://blog.youkuaiyun.com/yyx724916/article/details/8613527。这里只介绍NS2.34的安装部分:
1、将网上下载的ns-allinone-2.34.tar.gz拷贝到你cygwin目录下,我的是D:\cygwin\home\yyx(yyx是我的计算机用户名,要改成你的计算机用户名文件)输入tar xvfz ns-allinone-2.34.tar.gz,解压NS2压缩包.解压完成后要对D:\cygwin\home\yyx\ns-allinone-2.34\tcl8.4.18\unix中的tclUnixTime.c文件进行修改:
在该文件中增加如下红色部分定义:
#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 structThreadSpecificData {
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.
*/
如果没有添加这段红色的代码,在执行./install之后会出现
Makefile:1089: recipefor target `tclUnixTime.o' failed
的错误。
2、添加完成后cd到ns-allinone-2.34目录下,执行./install指令,然后就等待安装的完成。
安装完成后进行环境变量的设置:
在D:\cygwin\home\yyx(yyx是我的用户名文件)目录下的.bashrc文件最后一行添加如下代码:
export NS_HOME=/home/yyx/ns-allinone-2.34
export PATH=$NS_HOME/bin:$NS_HOME/tcl8.4.18/unix:$NS_HOME/tk8.4.18/unix:$NS_HOME/nam-1.14:$PATH
export LD_LIBRARY_PATH=$NS_HOME/otcl-1.13:$NS_HOME/lib:$NS_HOME/tcl8.4.18:$LD_LIBRARY_PATH
export TCL_LIBRARY=$NS_HOME/tcl8.4.18/library
记住:最好是在网上下载个ultraedit编辑器,在该编辑器里将这几行内容一个字一个字的敲进 .bashrvc文件里,不然会导致出错而找不到ns指令。
到这里NS2.34就安装好了,重新启动cygwin之后,输入ns就能看到%符号了,这就表示你已经安装成功了!