Ubuntu 10.04 下 安装 NS2.30 (个人修改少数错误)

 转自:http://hi.baidu.com/_dragonwarrior/blog/item/ba462fdc070fde43ccbf1a9e.html 

 

Ubuntu 10.04  安装 NS2.30 

1. NS2下载 

   OpenSourcesearch  NS2.30 

   我下载的版本是NS2.30 下载的文件为ns-allinone-2.30.tar.gz 

   下载完后将它解压缩到主文件夹下(我的是 /home/Soft/ns2): 

    tar xvfz ns-allinone-2.30.tar.gz 

2. 需要用到的软件包 

  build-essential 

  tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev 

  libxmu-dev 

3. 安装 

   cd/home/nuaa/Soft/ns-allinone-2.30 

   sudo ./install 

4. 出错处理

1). 

ld -shared -olibotcl.so otcl.o 

otcl.o: Infunction `OTclDispatch': 

/home/yanna/ns-allinone-2.30/otcl-1.12/otcl.c:495:undefined reference to `__stack_chk_fail_local' 

otcl.o: Infunction `Otcl_Init': 

/home/yanna/ns-allinone-2.30/otcl-1.12/otcl.c:2284:undefined reference to `__stack_chk_fail_local' 

ld: libotcl.so:hidden symbol `__stack_chk_fail_local' isn't defined 

ld: final linkfailed: Nonrepresentable section on output 

make: ***[libotcl.so] 错误 1cd ns-2.30;./validate 

otcl-1.12 makefailed! Exiting ... 

Seehttp://www.isi.edu/nsnam/ns/ns-problems.html for problems 

 

在官网上有解决方案,应该是个BUG,会在以后版本中解决:

otcl.o: In function `OTclDispatch': 

/home/ns/ns-allinone-2.30/otcl/otcl.c:495:undefined reference to `__stack_chk_fail_local' 

otcl.o: In function `Otcl_Init': 

/home/ns/ns-allinone-2.30/otcl/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: Nonrepresentablesection on output 

make: *** [libotcl.so] Error 1 

This error is because the linker being usedis "ld -shared" instead of"gcc -shared".  If you edit one line in otcl-1.12/configure,and rerun install , it should work: 

修改   /home/nuaa/Soft/ns2/ns-allinone-2.30/otcl-1.12/configure  文件


;; 

Linux*) 

SHLIB_CFLAGS="-fpic"

SHLIB_LD="ld-shared"      SHLIB_LD="gcc-shared" 

SHLIB_SUFFIX=".so"

DL_LIBS="-ldl"

SHLD_FLAGS=""

This will be fixed in future revisions ofns-2.    改完后重新安装。

2). 

Tcl.cc:In member function ‘void Tcl::eval(char*)’:
Tcl.cc:182: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc: In member function ‘int TclObject::traceVar(const char*, TclObject*)’:
Tcl.cc:421: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc: In static member function ‘static int TclClass::create_shadow(void*,Tcl_Interp*, int, const char**)’:
Tcl.cc:509: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc:511: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc: In static member function ‘static int TclClass::dispatch_instvar(void*,Tcl_Interp*, int, const char**)’:
Tcl.cc:566: error: invalid conversion from ‘const char*’ to ‘char*’
Tcl.cc:571: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc: In member function ‘virtual void TclClass::bind()’:
Tcl.cc:603: warning: deprecated conversion from string constant to ‘char*’
Tcl.cc:605: warning: deprecated conversion from string constant to ‘char*’
make: *** [Tcl.o] 
错误 1
tclcl-1.18 make failed! Exiting ...

*******************************************************原作者解决方法开始************************************************************

由于gcc版本过高引起的编译问题 gcc-4.4  --> gcc-4.3

 1. sudo apt-get install gcc-4.3

安装了之后,系统之中就存在两个GCC版本4.44.3,可以通过ls命令查看: 

   1. ls /usr/bin/gcc*   

   2. /usr/bin/gcc  /usr/bin/gcc-4.3  /usr/bin/gcc-4.4  /usr/bin/gccbug-4.3 

但是这时系统默认的GCC还是4.4版的,可以通过gcc -v查看版本号 

设置GCC4.3GCC4.4的可选项,在终端输入以下命令 

   1.  sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 40

   2.  sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 30  

现在设置GCC的默认版本,输入下面命令: 

sudoupdate-alternatives --config gcc 

我得到的结果: 

There are 2choices for the alternative gcc (providing /usr/bin/gcc). 

  Selection   Path              Priority   Status 

------------------------------------------------------------

* 0            /usr/bin/gcc-4.4   40       auto mode 

  1           /usr/bin/gcc-4.3   30        manual mode 

  2           /usr/bin/gcc-4.4   40        manual mode 

然后输入“1”,再查看一下gcc的版本,已经变成4.3的了~~~~ 

同样对于g++也可以使用同样的方法从4.4高版本切换到4.3低版本。。。

*******************************************************原作者解决方法结束************************************************************

*******************************************************我的解决方法开始************************************************************

由于我按照上述步骤装了gcc-4.3的不行,又装了gcc-4.1的仍然不行,于是就干脆进到tclcl-1.18文件夹下查找原因,最终发现的确因为是编译器版本过高引起的,但是是由于g++版本过高,而不是gcc,解决步骤如下:

1. sudo apt-get install g++-4.1

2. ls /usr/bin/g++*

得到结果:

/usr/bin/g++  /usr/bin/g++-4.1  /usr/bin/g++-4.4

3. update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 40

4. update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.1 30

5. sudo update-alternatives --config g++

得到结果:
  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/g++-4.4   40        auto mode
  1            /usr/bin/g++-4.1   30        manual mode
  2            /usr/bin/g++-4.4   40        manual mode
选择1即可

 

5. 配置环境变量 

   安装完成后会看到修改环境变量的提示: 

Please put /home/nuaa/Soft/ns2/ns-allinone-2.30/bin,/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/unix,home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/unix" 

into your PATH environment; so that you'llbe able to run itm/tclsh/wish/xgraph. 

IMPORTANT NOTICES: 

(1) You MUST put /home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/otcl-1.12,/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/lib

   into your LD_LIBRARY_PATH environment variable. 

    Ifit 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/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/libraryinto your TCL_LIBRARY environmental 

   variable. Otherwise ns/nam will complain during startup. 

After these steps, you can now run the nsvalidation suite with 

cd ns-2.30; ./validate 

For trouble shooting, please first read nsproblems page 

http://www.isi.edu/nsnam/ns/ns-problems.html.Also search the ns mailing list archive 

for related posts . 

   回到主文件夹,修改bash配置文件.bashrc 

  sudo gedit .bashrc 

   在文件最后加上: 

PATH="$PATH:/home/nuaa/Soft/ns2/ns-allinone-2.30/bin:/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/unix:/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/unix"

LD_LIBRARY_PATH="/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/otcl-1.12:/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/lib"

TCL_LIBRARY="$TCL_LIBRARY:/home/nuaa/Soft/ns2/ns-allinone-2.30/tcl8.4.13/library"

6. 安装验证 

   安装结束后的提示中也告诉我们如何验证是否正确安装: 

   cdns-2.30 

  ./validate 

   另外,也可以打开一个新终端进行试运行: 

   输入ns,如果显示一个%则说明已正确安装。如果提示“command not found”则重新启动试试。


你可能感兴趣的:(Ubuntu 10.04 下 安装 NS2.30 (个人修改少数错误))