前言
在Mac OS 10.9这个最新的系统下安装NS-2.35存在一些小困难,相信困扰到一些同学了。网上有针对10.6/7的patch,但是在OS 10.9上,并且更新了新的Xcode后,会因为编译器的原因导致一些错误。本人看了很多老外也在stack overflow上求助。
方法和步骤
我一番折腾之后,修复了所有安装过程出现的问题,为了下次安装可以省事,就干脆直接制作了一个patch,方便自己也方便他人。同时对install脚本进行改进,自动增加环境变量(MacOs)。
安装步骤:
安装之前请先安装xQuartz和patch。(patch通过brew或者ports安装,不懂的自己先搜一下,相当于yum和apt-get)
1.解压ns-allinone-2.35.tar.gz。
2.复制patch文件到ns-allinone-2.35目录下。
3.执行patch -p1 -i macos10.9.patch。
4.执行./install进行安装。
不出意外的话,应该直接安装成功,并且自动添加环境变量。
修正:
之前的补丁在重新执行configure脚本后会报Undefined symbols for architecture x86_64这个错误,分析了原因发现是LDFLAGS的原因。需要加载CoreFoundation框架。
即LDFLAGS =
-framework CoreFoundation,这个本来在configure里面是存在的,但是configure脚本的判断逻辑不对,它判断mac的内核如果是Darwin 8、9才加载这个框架。由于我不做Mac开发,不太清楚框架的用途。总之,修正后的补丁解决了这个问题。还有,没事不要乱对ns进行configure。
补丁:
下载:
https://code.csdn.net/snippets/153117/master/download
感谢CSDN的代码片功能。
直接贴代码:保存为macos10.9.patch
macos10.9.patch
diff -aur s-allinone-2.35.orig/ns-2.35/configure ns-allinone-2.35/ns-2.35/configure
--- ns-allinone-2.35.orig/ns-2.35/configure 2011-11-05 01:29:46.000000000 +0800
+++ ns-allinone-2.35/ns-2.35/configure 2014-01-12 14:30:52.000000000 +0800
@@ -9301,7 +9301,7 @@
fi
case $system in
- Darwin-7.*|Darwin-8.*)
+ Darwin-7.*|Darwin-8.*|Darwin-12.*|Darwin-13.*)
V_LIB="$V_LIB -framework CoreFoundation"
esac
diff -aur s-allinone-2.35.orig/install ns-allinone-2.35/install
--- ns-allinone-2.35.orig/install 2011-11-05 01:18:22.000000000 +0800
+++ ns-allinone-2.35/install 2014-01-14 15:34:34.000000000 +0800
@@ -200,6 +200,7 @@
echo "Darwin detected";
DYLD_LIBRARY_PATH=$CUR_PATH/tcl$TCLVER/unix:$CUR_PATH/tk$TKVER/unix:$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH
+ export LDFLAGS="-framework CoreFoundation"
test_darwin=true
fi
@@ -565,11 +566,6 @@
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 --with-tcl-ver=$TCLVER --with-tk-ver=$TKVER || die "Nam configuration failed! Exiting ...";
else
@@ -671,14 +667,19 @@
echo ""
echo "----------------------------------------------------------------------------------"
-echo ""
+echo "The install script will automatically add environment variable to your system,if you run \"ns\" and then system says \"command not found\", you should check your environment varible (~/.bash_profile or ~/.bash_rc)"
echo "Please put $CUR_PATH/bin:$CUR_PATH/tcl$TCLVER/unix:$CUR_PATH/tk$TKVER/unix"
echo "into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph."
+#Add env var
+echo "export PATH=$PATH:$CUR_PATH/bin:$CUR_PATH/tcl$TCLVER/unix:$CUR_PATH/tk$TKVER/unix" >>~/.bash_profile
echo ""
echo "IMPORTANT NOTICES:"
echo ""
echo "(1) You MUST put $CUR_PATH/otcl-$OTCLVER, $CUR_PATH/lib, "
echo " into your LD_LIBRARY_PATH environment variable."
+#Add env var
+echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUR_PATH/otcl-$OTCLVER:$CUR_PATH/lib" >>~/.bash_profile
+
echo " If it complains about X libraries, add path to your X libraries "
echo " into LD_LIBRARY_PATH."
echo " If you are using csh, you can set it like:"
@@ -687,6 +688,9 @@
echo " export LD_LIBRARY_PATH=
"
echo ""
echo "(2) You MUST put $CUR_PATH/tcl$TCLVER/library into your TCL_LIBRARY environmental"
+#Add env var
+echo "export TCL_LIBRARY=$TCL_LIBRARY:$CUR_PATH/tcl$TCLVER/library " >>~/.bash_profile
+
echo " variable. Otherwise ns/nam will complain during startup."
echo ""
echo ""
diff -aur ns-allinone-2.35.orig/nam-1.15/Makefile.in ns-allinone-2.35/nam-1.15/Makefile.in
--- ns-allinone-2.35.orig/nam-1.15/Makefile.in 2012-09-07 14:36:27.000000000 -0700
+++ ns-allinone-2.35/nam-1.15/Makefile.in 2012-09-07 14:45:22.000000000 -0700
@@ -72,7 +72,7 @@
BLANK = # make a blank space. DO NOT add anything to this line
AR = ar rc $(BLANK)
LINK = $(CPP)
-LDFLAGS =
+LDFLAGS = @LDFLAGS@
LDOUT = -o $(BLANK)
PERL = perl
RM = rm -f
diff -aur ns-allinone-2.35.orig/ns-2.35/indep-utils/webtrace-conv/dec/Makefile.in ns-allinone-2.35/ns-2.35/indep-utils/webtrace-conv/dec/Makefile.in
--- ns-allinone-2.35.orig/ns-2.35/indep-utils/webtrace-conv/dec/Makefile.in 2012-09-07 14:36:41.000000000 -0700
+++ ns-allinone-2.35/ns-2.35/indep-utils/webtrace-conv/dec/Makefile.in 2012-09-07 14:40:36.000000000 -0700
@@ -54,7 +54,7 @@
CC = @CXX@
INCLUDE = -I. @V_INCLUDES@
CFLAGS = @V_CCOPT@ -DCPP_NAMESPACE=@CPP_NAMESPACE@
-LDFLAGS = @V_STATIC@
+LDFLAGS = @LDFLAGS@
LIBS = @V_LIB_TCL@ @V_LIB@ @LIBS@
INSTALL = @INSTALL@
diff -aur ns-allinone-2.35.orig/ns-2.35/indep-utils/webtrace-conv/epa/Makefile.in ns-allinone-2.35/ns-2.35/indep-utils/webtrace-conv/epa/Makefile.in
--- ns-allinone-2.35.orig/ns-2.35/indep-utils/webtrace-conv/epa/Makefile.in 2012-09-07 14:36:42.000000000 -0700
+++ ns-allinone-2.35/ns-2.35/indep-utils/webtrace-conv/epa/Makefile.in 2012-09-07 14:40:22.000000000 -0700
@@ -51,7 +51,7 @@
INCLUDE = -I. @V_INCLUDES@
CFLAGS = @V_CCOPT@ -DCPP_NAMESPACE=@CPP_NAMESPACE@
-LDFLAGS = @V_STATIC@
+LDFLAGS = @LDFLAGS@
LIBS = @V_LIB_TCL@ @V_LIB@ @LIBS@
INSTALL = @INSTALL@
diff -aur ns-allinone-2.35.orig/ns-2.35/indep-utils/webtrace-conv/nlanr/Makefile.in ns-allinone-2.35/ns-2.35/indep-utils/webtrace-conv/nlanr/Makefile.in
--- ns-allinone-2.35.orig/ns-2.35/indep-utils/webtrace-conv/nlanr/Makefile.in 2012-09-07 14:36:42.000000000 -0700
+++ ns-allinone-2.35/ns-2.35/indep-utils/webtrace-conv/nlanr/Makefile.in 2012-09-07 14:40:02.000000000 -0700
@@ -51,7 +51,7 @@
CC = @CXX@
INCLUDE = -I. -I../../.. @V_INCLUDES@
CFLAGS = @V_CCOPT@ -DCPP_NAMESPACE=@CPP_NAMESPACE@
-LDFLAGS = @V_STATIC@
+LDFLAGS = @LDFLAGS@
LIBS = @V_LIB_TCL@ @V_LIB@ @LIBS@
INSTALL = @INSTALL@
diff -aur ns-allinone-2.35.orig/ns-2.35/indep-utils/webtrace-conv/ucb/Makefile.in ns-allinone-2.35/ns-2.35/indep-utils/webtrace-conv/ucb/Makefile.in
--- ns-allinone-2.35.orig/ns-2.35/indep-utils/webtrace-conv/ucb/Makefile.in 2012-09-07 14:36:42.000000000 -0700
+++ ns-allinone-2.35/ns-2.35/indep-utils/webtrace-conv/ucb/Makefile.in 2012-09-07 14:39:41.000000000 -0700
@@ -29,7 +29,7 @@
INCLUDE = -I. @V_INCLUDES@
CFLAGS = @V_CCOPT@ -DCPP_NAMESPACE=@CPP_NAMESPACE@
-LDFLAGS = @V_STATIC@
+LDFLAGS = @LDFLAGS@
LIBS = @V_LIB_TCL@ @V_LIB@ @LIBS@
INSTALL = @INSTALL@
--- ns-allinone-2.35.orig/otcl-1.14/Makefile.in 2012-09-07 14:37:37.000000000 -0700
+++ ns-allinone-2.35/otcl-1.14/Makefile.in 2012-09-07 21:20:06.000000000 -0700
@@ -8,6 +8,7 @@
CFLAGS= @CFLAGS@
RANLIB= @RANLIB@
INSTALL= @INSTALL@
+LDFLAGS= @LDFLAGS@
#
# how to compile, link, and name shared libraries
@@ -16,7 +17,7 @@
SHLIB_LD= @SHLIB_LD@
SHLIB_CFLAGS= @SHLIB_CFLAGS@
SHLIB_SUFFIX= @SHLIB_SUFFIX@
-SHLD_FLAGS= @DL_LD_FLAGS@
+SHLD_FLAGS= @LDFLAGS@
DL_LIBS= @DL_LIBS@
SHLIB_LD_LIBS = @SHLIB_LD_LIBS@
diff -aur ns-allinone-2.35.orig/ns-2.35/common/agent.cc ns-allinone-2.35/ns-2.35/common/agent.cc
--- ns-allinone-2.35.orig/ns-2.35/common/agent.cc 2010-03-08 13:54:49.000000000 +0800
+++ ns-allinone-2.35/ns-2.35/common/agent.cc 2014-01-12 02:21:17.000000000 +0800
@@ -51,7 +51,7 @@
#include "nix/nixnode.h"
#endif //HAVE_STL
-
+using namespace NIX;
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
diff -aur ns-allinone-2.35.orig/ns-2.35/common/node.cc ns-allinone-2.35/ns-2.35/common/node.cc
--- ns-allinone-2.35.orig/ns-2.35/common/node.cc 2002-05-31 01:44:03.000000000 +0800
+++ ns-allinone-2.35/ns-2.35/common/node.cc 2014-01-12 02:58:36.000000000 +0800
@@ -42,11 +42,8 @@
#include "address.h"
#include "config.h"
-#ifdef HAVE_STL
-#include "nix/nixnode.h"
-#endif //HAVE_STL
#include "node.h"
-
+using namespace NIX;
static class LinkHeadClass : public TclClass {
public:
LinkHeadClass() : TclClass("Connector/LinkHead") {}
diff -aur ns-allinone-2.35.orig/ns-2.35/common/node.h ns-allinone-2.35/ns-2.35/common/node.h
--- ns-allinone-2.35.orig/ns-2.35/common/node.h 2002-05-31 01:44:03.000000000 +0800
+++ ns-allinone-2.35/ns-2.35/common/node.h 2014-01-12 03:04:44.000000000 +0800
&#