1、首先是下載下傳ns-allinone-2.34.tar.gz。去官網或者網上找都有。
2、先更新一下系統。在終端輸入:
sudo apt-get update #更新源清單
sudo apt-get upgrade #更新已安裝的包
sudo apt-get dist-upgrade #更新軟體,更新系統
3、安裝幾個需要使用的軟體包
sudo apt-get install build-essential
sudo apt-get install tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev #for tcl and tk
sudo apt-get install libxmu-dev libxmu-headers #for nam
4、然後可以進行安裝:
sudo cp /home/ww/ns-allinone-2.34.tar.gz /usr #将壓縮檔案放到安裝目錄下
cd /usr/
sudo tar -zxvf ns-allinone-2.34.tar.gz
cd ./ns-allinone-2.34
sudo./install
然後看到指令行非常養眼地快速翻滾。在結束時突然報錯:
ld -shared-o libotcl.so otcl.o
otcl.o: Infunction `OTclDispatch':
/usr/ns-allinone-2.34/otcl-1.13/otcl.c:495:undefined reference to `__stack_chk_fail_local'
otcl.o: Infunction `Otcl_Init':
/usr/ns-allinone-2.34/otcl-1.13/otcl.c:2284:undefined reference to `__stack_chk_fail_local'
ld:libotcl.so: hidden symbol `__stack_chk_fail_local' isn'tdefined
ld: finallink failed: Nonrepresentable section on output
make: ***[libotcl.so] 錯誤 1
otcl-1.13make failed! Exiting ...
Seehttp://www.isi.edu/nsnam/ns/ns-problems.html forproblems
錯誤原因及發現解決辦法:
gcc 4.0版本以前是用ld -share來生成共享庫的,但是到了4.0以上的版本(我的為gcc version4.4.1),這個指令改為了gcc -share即可
解決過程:
cd /usr/ns-allinone-2.34/otcl-1.13
sudo configure.in
把77行處的
SHLIB_LD="ld-shared"
改為
SHLIB_LD="gcc -shared"
儲存退出,然後
sudo configure
把6304行
原來為
SHLIB_LD="ld-shared"
改為
SHLIB_LD="gcc -shared"
儲存退出,然後
cd /usr/ns-allinone-2.34
回到目錄ns-allinone-2.34下運作
sudo./install
如果正确安裝可以看到提示:
----------------------------------------------------------------------------------
5、設定環境變量和善後工作:
用cd進入目錄/home/ww(ww是我的使用者名),然後
sudo gedit .bashrc
在檔案末尾加入:
PATH="$PATH:/usr/ns-allinone-2.34/bin:/usr/ns-allinone-2.34/tcl8.4.18/unix:/usr/ns-allinone-2.34/tk8.4.18/unix"
LD_LIBRARY_PATH="/usr/ns-allinone-2.34/otcl-1.13:/usr/ns-allinone-2.34/lib"
TCL_LIBRARY="$TCL_LIBRARY:/usr/ns-allinone-2.34/tcl8.4.18/library"
儲存退出(上述内容在安裝結束後的提示中有,見粗體部分)。
6、驗證
打開一個新終端,輸入ns,如果出現%,則說明安裝成功。
也可以進入/usr/ns-allinone-2.34/ns-2.34/,輸入./validate驗證。
到此。上面的/usr目錄記得都要用自己的安裝路徑替換。