Oct 15, 2010

重温NS2-基于Macintosh的架设方法



最近一直在写项目报告,枯燥且头疼的工作。昨天忙里偷闲,突然很想把NS2在Mac机上装一次。本科做毕业设计的时候,曾在WinXP虚拟机的Linux上安装过,前后折腾了大概一个月,太痛苦了。由于Mac OS的内核是基于UNIX的,所以我猜想安装过程应该不会与在Windows上那么繁琐。结果确实让人很兴奋,只用了不到一天就把NS2稳稳地架在了Mac OS X v10.6。终于明白为什么几乎所有的系统开发设计人员都倍加推崇Mac OS,继承UNIX的血统就是很赞,绝对是利器。下面是我的操作记录,
1)配置Xcode环境
在apple官网下载免费的Xcode http://developer.apple.com/technologies/tools/xcode.html,不要只安装gcc编译器,还应选择X11;安装之后会得到X11包含的所有库文件,他们被放在/Developer/SDKs/MacOSX10.6.sdk/X11R6/lib目录下。
2)下载NS2并配置子模块
可以在这个地址下载NS2.34版本,http://sourceforge.net/project/showfiles.php?group_id=149743;之后命令行解压,tar xzvf ns-allinone-2.34.tar.gz;修改在tcl, tctcl, otcl, nam目录下的configure文件,A)在各个文件中的xlibdirs末尾添加路径“/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/lib”,B)在各个文件中的xincdirs末尾添加路径“/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include”
3)配置NS2
在ns-allinone-2.34主目录下,修改configure文件如下,
#! /bin/sh # # Copyright (C) 2000 by USC/ISI # All rights reserved. # # Redistribution and use in source and binary forms are permitted # provided that the above copyright notice and this paragraph are # duplicated in all such forms and that any documentation, advertising # materials, and other materials related to such distribution and use # acknowledge that the software was developed by the University of # Southern California, Information Sciences Institute. The name of the # University may not be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # # $Header: /cvsroot/nsnam/ns-2/allinone/install,v 1.31 2007/03/10 23:40:05 tom_henderson Exp $
X_INCL = /Developer/SDKs/MacOSX10.6.sdk/usr/X11R6/include X_LIBS = /Developer/SDKs/MacOSX10.6.sdk/usr/X11R6/lib MACOS_CONF = "--x-include=$X_INCL --x-libraries=$X_LIBS"
die() { echo "$@" 1>&2 test ! -z "$blame" && echo "$blame" 1>&2 exit 1 }
..........
# Build otcl
echo "============================================================"
echo "* Build OTcl-$OTCLVER"
echo "============================================================"
cd ./otcl-$OTCLVER blame='Please check http://www.isi.edu/nsnam/ns/ns-problems.html for common problems and bug fixes.' if [ "${test_cygwin}" = "true" ]; then ./configure --x-libraries=/usr/X11R6/lib --x-includes=/usr/X11R6/include || die "otcl-$OTCLVER configuration failed! Exiting ..."; else ./configure --x-libraries=/usr/X11R6/lib --x-includes=/usr/X11R6/include CFLAGS="-framework CoreFoundation" || die "otcl-$OTCLVER configuration failed! Exiting ..."; fi
...............
# Build tclcl
echo "============================================================" echo "* Build Tclcl-$TCLCLVER" echo "============================================================"
cd ./tclcl-$TCLCLVER
if [ "${test_cygwin}" = "true" ]; then ./configure --x-libraries=/usr/X11R6/lib --x-includes=/usr/X11R6/include || die "tclcl-$TCLCLVER configuration failed! Exiting ..."; else ./configure --x-libraries=/usr/X11R6/lib --x-includes=/usr/X11R6/include --with-otcl=../otcl-$OTCLVER || die "tclcl-$TCLCLVER configuration failed! Exiting ..." fi
..........
# John's hack test -f ./otcl-$OTCLVER/libotcl.a && rm ./otcl-$OTCLVER/libotcl.so
echo "============================================================" echo "* Build ns-$NSVER" echo "============================================================" cd ./ns-$NSVER if [ -f Makefile ] ; then make distclean fi
if [ "${test_cygwin}" = "true" ]; then ./configure --x-libraries=/usr/X11R6/lib --x-includes=/usr/X11R6/include || die "Ns configuration failed! Exiting ..."; else ./configure --x-libraries=/usr/X11R6/lib --x-includes=/usr/X11R6/include LIBS="-framework CoreFoundation"--with-otcl=../otcl-$OTCLVER --with-tclcl=../tclcl-$TCLCLVER || die "Ns configuration failed! Exiting ..."; fi
...................
# Build nam echo "============================================================" echo "* Build nam-$NAMVER" echo "============================================================" ln -s otcl-$OTCLVER otcl ln -s tclcl-$TCLCLVER tclcl cd ./nam-$NAMVER
# XXX temporary OS X hack if [ "${test_darwin}" = "true" ]; then ln -s /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation libcorefoundation.dylib fi
if [ "${test_cygwin}" = "true" ]; then ./configure --x-libraries=/usr/X11R6/lib --x-includes=/usr/X11R6/include --with-tclcl=$CUR_PATH/tclcl-$TCLCLVER || die "Nam configuration failed! Exiting ..."; else ./configure --x-libraries=/usr/X11R6/lib --x-includes=/usr/X11R6/include V_LIBS="-framework CoreFoundation" --with-otcl=../otcl-$OTCLVER --with-tclcl=../tclcl-$TCLCLVER || die "Nam configuration failed! Exiting ..."; fi
..........
4)在命令行,切换到ns-allinone-2.34主目录下,运行"./install"开始代码编译。
5)配置环境变量
在命令行运行“echo "PATH=/Users/username/ns2/ns-allinone-2.34/bin:$PATH" > .bashrc”;
切换到用户home目录下,用"vi .profile"打开.profile文件,插入以下环境变量,
export PATH=$PATH:/Users/username/ns-allinone-2.34/bin:/Users/username/ns-allinone-2.34/tcl8.4.18/unix:/Users/username/ns-allinone-2.34/tk8.4.18/unix
export LD_LIBRARY_PATH=/Users/username/ns-allinone-2.34/otcl-1.13:/Users/username/ns-allinone-2.34/lib
export TCL_LIBRARY=/Users/username/ns-allinone-2.34/tcl8.4.18/library
PS:home目录下不一定有该文件,如果没有.profile文件,则用相同步骤可创建一个.profile文件
在命令行输入"source .profile",无错误提示返回。
6)确认架设正确
可用命令"cd ns-allinone-2.34/ns-2.34/tcl/ex/"切换至该目录下,之后用"ns simple.tcl"运行演示程序。
一天与一个月,这可能也说明了苹果与微软现在的差距