1. 程式人生 > >在ubuntu14.04中安裝和配置NS-2

在ubuntu14.04中安裝和配置NS-2

1、更新系統:在終端輸入如下命令

sudo app-get update #更新源列表
sudo app-get upgrade #更新已經安裝的包
sudo app-get dist-upgrade #更新軟體,升級系統

2、安裝幾個需要的包

sudo apt-get install build-essential
sudo apt-get install tcl8.5 tcl8.5-dev tk8.5 tk8.5-dev #for tcl and tk
sudo apt-get install libxmu-dev libxmu-headers #for nam

3、下載安裝包,並複製到需要安裝的目錄,在這裡需要取得root許可權才可以安裝


官網下載地址:http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.35/ns-allinone-2.35.tar.gz/download,這裡下載allinone

tar xvfz ns-allinone-2.35.tar.gz
cd ns-allinone-2.35

./install #進行安裝

安裝過程中出現錯誤:

In file included from linkstate/ls.cc:67:0:
linkstate/ls.h: In instantiation of ‘void LsMap::eraseAll() [with Key = int; T = LsIdSeq]’:
linkstate/ls.cc:396:28: required from here
linkstate/ls.h:137:20: error: ‘erase’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
linkstate/ls.h:137:20: note: declarations in dependent base ‘std::map, std::allocator > >’ are not found by unqualified lookup
linkstate/ls.h:137:20: note: use ‘this->erase’ instead
make: *** [linkstate/ls.o] Error 1
Ns make failed!

解決方法:
將 ns/ns-2.35/linkstate/ls.h中的137行void eraseAll() { erase(baseMap::begin(), baseMap::end()); }改為 void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); }
然後重新執行 sudo ./install

4、配置環境變數

在當前使用者目錄下,編輯.bashrc檔案

sudo vim .bashrc

在檔案末尾新增

# add path for ns2
export PATH="$PATH:/home/liushun/ns-allinone-2.35/bin:/home/安裝資料夾名/ns-allinone-2.35/tcl8.5.10/unix:/home/安裝資料夾名/ns-allinone-2.35/tk8.5.10/unix"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/安裝資料夾名/ns-allinone-2.35/otcl-1.14:/home/安裝資料夾名/ns-allinone-2.35/lib"
export TCL_LIBRARY="$TCL_LIBRARY:/home/安裝資料夾名/ns-allinone-2.35/tcl8.5.10/library"


5、驗證安裝


進入控制檯,輸入ns,這時會提示安裝ns2,根據提示輸入

sudo apt-get install ns2

再次輸入ns,出現%,說明安裝成功

輸入nam,報錯,這時提示安裝nam,根據提示輸入

sudo apt-get install nam

如果以上命令失效,可先輸入

sudo apt-get update #進行更新