NS2安裝終結版

 

http://blog.sina.com.cn/s/blog_6ddfdc6701018fk1.html

最近一直在使用ns2,遇到各種問題,需要各種重裝,特此整理一下安裝過程。
首先下載到ns-allinone-2.34.tar.gz,這個網上到處都是。
然後開始在終端裏輸入命令,獲取ns2需要的相關軟件:
sudo apt-get install build-essential
sudo apt-get install tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev
sudo apt-get install libxmu-dev libxmu-headers
sudo apt-get install xorg-dev g++ xgraph

sudo apt-get install g++-4.4
===============================

然後解壓ns-allinone-2.34.tar.gz,放到你指定的目錄。
檢查你的gcc版本,如果gcc版本大於4.0(大部分人的都是,建議直接改),要在執行./install之前作出一些修改。
gcc4.0版本以前是用ld-share來生成共享庫的,但是到了4.0以上的版本,這個命令改爲了gcc-share。
修改命令如下:
cdns-allinone-2.34/otcl-1.13
  
  sudogedit configure.in
  把77行處的
  SHLIB_LD="ld-shared"
  改爲
  SHLIB_LD="gcc-shared"
  保存退出,然後
  
  sudogedit configure
  把6304行(Ctrl+i跳到6304行)的
  SHLIB_LD="ld-shared"
  改爲
  SHLIB_LD="gcc-shared"
  保存退出,然後
  cdns-allinone-2.34 #到安裝目錄
  sudo./install #開始安裝
如果沒有更改直接安裝,就會出現這樣的錯誤:
ld: libotcl.so: hidden symbol `__stack_chk_fail_local' isn't defined
ld: final link failed: Bad value
make: *** [libotcl.so] Error 1
這只是有可能出現的第一個錯誤,接下來還有更多的錯誤等着你!(所以要整理出這麼一份東西來。。。)
=======================================================================================
錯誤一:安裝NS2.34過程中出現如下的錯誤:
tools/ranvar.cc: In member function ‘virtual double GammaRandomVariable::value()’:
tools/ranvar.cc:219:70: error: cannot call constructor ‘GammaRandomVariable::GammaRandomVariable’ directly
tools/ranvar.cc:219:70: error:  for a function-style cast, remove the redundant ‘::GammaRandomVariable’
make: *** [tools/ranvar.o]錯誤1
Ns make failed!
See http://www.isi.edu/nsnam/ns/ns-problems.html for problems

 這是由於gcc版本提高後對類內部函數調用的簡化造成的不兼容,解決方法如下:

 在ns-allinone-2.34/ ns-2.34/tools文件夾下,找到報錯提示中的ranvar.cc文件,打開找到對應的219行刪除::GaammaRandomVariable,保存,

即:將219行的

return GammaRandomVariable::GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);

改爲:

return GammaRandomVariable(1.0 + alpha_, beta_).value() * pow (u, 1.0 / alpha_);

 然後保存退出,重新安裝ns2.

======================================================================================

錯誤二

In file included from mac/mac-802_11Ext.cc:66:0:

mac/mac-802_11Ext.h: In member function ‘u_int32_t PHY_MIBExt::getHdrLen11()’:

mac/mac-802_11Ext.h:175:19: error: expected primary-expression before ‘struct’

mac/mac-802_11Ext.h:175:41: error: ‘dh_body’ was not declared in this scope

mac/mac-802_11Ext.h:175:51: error: ‘offsetof’ was not declared in this scope

mac/mac-802_11Ext.h:177:3: warning: control reaches end of non-void function [-Wreturn-type]

make: *** [mac/mac-802_11Ext.o] Error 1


Ns make failed!

下面是網上找得關於本問題的解決方案:

If you get error like:

mac/mac-802_11Ext.h: In member function ‘u_int32_t PHY_MIBExt::getHdrLen11()’:
mac/mac-802_11Ext.h:176:19: error: expected primary-expression before ‘struct’
mac/mac-802_11Ext.h:176:41: error: ‘dh_body’ was not declared in this scope
mac/mac-802_11Ext.h:176:51: error: ‘offsetof’ was not declared in this scope

open that file and add

#include <cstddef>

to the header files.
在ns-allinone-2.34\ns-2.34\mac\mac-802_11Ext.h 文件添加#include <cstddef>
然後重新安裝,就OK了。

=============================================================================

錯誤三:

mobile/nakagami.cc: In member function ‘virtual double Nakagami::Pr(PacketStamp*, PacketStamp*, WirelessPhy*)’:

mobile/nakagami.cc:183:73: error: cannot call constructor ‘ErlangRandomVariable::ErlangRandomVariable’ directly

mobile/nakagami.cc:183:73: error:  for a function-style cast, remove the redundant ‘::ErlangRandomVariable’

mobile/nakagami.cc:185:67: error: cannot call constructor ‘GammaRandomVariable::GammaRandomVariable’ directly

mobile/nakagami.cc:185:67: error:  for a function-style cast, remove the redundant ‘::GammaRandomVariable’

make: *** [mobile/nakagami.o]錯誤1

Ns make failed!

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

解決方法:

在ns-allinone-2.34/ ns-2.34/ mobile文件夾下,找到報錯提示中的nakagami.cc文件,打開找到對應的183行刪除::ErlangRandomVariable,保存,

即:將183行的

resultPower = ErlangRandomVariable::ErlangRandomVariable(Pr/m, int_m).value();

改爲:

resultPower = ErlangRandomVariable(Pr/m, int_m).value();

在ns-allinone-2.34/ ns-2.34/ mobile文件夾下,找到報錯提示中的nakagami.cc文件,打開找到對應的185行刪除::GammaRandomVariable,保存,

即:將185行的

resultPower = GammaRandomVariable::GammaRandomVariable(m, Pr/m).value();

改爲:

resultPower = GammaRandomVariable(m, Pr/m).value();

 

重新在ns目錄下鍵入$ ./install安裝,再次出現同類問題時,仿照此次解決方法,找到對應的文件和行數,修改即可。直到安裝成功。

=======================================================================================

到這裏安裝終於成功了,不要忘記添加環境變量
在/home目錄下
sudo gedit .bashrc在彈出的窗口文件最後輸入export PATH=$PATH:/home/yourfile/ns-allinone-2.34/bin:/home/yourfile/ns-allinone-2.34/tcl8.4.18/unix:/home/yourfile/ns-allinone-2.34/tk8.4.18/unix
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/yourfile/ns-allinone-2.34/otcl-1.13:/home/yourfile/ns-allinone-2.34/lib

export TCL_LIBRARY=$TCL_LIBRARY:/home/yourfile/ns-alllinone-2.34/tcl8.4.18/library

============================

驗證(測試)
   (1)打開一個新的終端
   (2)輸入ns並回車
   $ns (如果正常,會出現"%"操作提示符,如果顯示還沒有安裝ns2,可以先安裝nam,再測試ns)
   (3)輸入一段測試用的Tcl腳本代碼進行測試
   %puts "Hello World" (輸出Hello World字符串)
   Hello World (如果正確,會顯示Hello World)
   % (然後跳到下一個"%"提示符等待下一條指令輸入)

============================
安裝nam
   cd ns-allinone-2.34/nam-1.14
   ./configure
   make
   sudo make install (至此,nam安裝好)

在終端中輸入nam命令,彈出nam界面則說明nam安裝好了
(本人nam安裝完成後一直沒有辦法正確使用,照網上打過補丁之後依舊是老毛病,今天偶然使用這個方法安裝竟然就奇蹟般的可以使用了,在此表示誠摯的感謝,淚流滿面啊!!!)
 

到此ns2終於安裝好!!

如果遇到其他安裝過程中的問題還會繼續更新本文。


PS: ns2相關學習資料網址

百思論壇

http://www.baisi.net/forum-440-1.html

向ns2中添加新的隊列算法

http://www.cs.cmu.edu/~istoica/csfq/step-by-step.html#fred-ref

ns2教學手冊

http://hpds.ee.ncku.edu.tw/~smallko/ns2/ns2.htm


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章