1.首先去http://www./nsnam/ns/ns-build.html下載ns-allinone-2.35.tar.gz 2.
拷貝到用戶目錄下 如 /home/mingyong/ 3. 更新一下系統 sudo apt-get update #更新源列表 sudo apt-get upgrade #更新已安裝的包 4. 安裝幾個依賴文件 sudo apt-get install build-essential sudo apt-get install tcl8.5 tcl8.5-dev tk8.5 tk8.5-dev
sudo apt-get install libxmu-dev libxmu-headers
5. 解壓 tar -xvzf ns-allinone-2.35.tar.gz
mv ns-allinone-2.35 ns #將文件夾ns-allinone-2.35改為ns,方便以后操作 6. 安裝 cd ns sudo ./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
幾分鐘后出現下圖,表明安裝好了

7. 設置環境變量 sudo gedit ./bashrc 在文件尾加入: export PATH="$PATH:/home/mingyong/ns/bin:/home/mingyong/ns/tcl8.5.10/unix:/home/mingyong/ns/tk8.5.10/unix"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/mingyong/ns/otcl-1.14:/home/mingyong/ns/lib"
export TCL_LIBRARY="$TCL_LIBRARY:/home/mingyong/ns/tcl8.5.10/library"
8 新開啟一個終端,輸入ns,出現如下圖表面安裝成功,也可以進入 ns/ns-2.35, 輸入./validate進行驗證

出現問題匯總:
1. NS2下載
在OpenSource中search NS2.30
我下載的版本是NS2.30, 下載的文件為ns-allinone-2.30.tar.gz。 下載完后將它解壓縮到主文件夾下(我的是 /home/nuaa/Soft/): 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/nsusr/ns-allinone-2.30 sudo ./install
*注意當出現類似tk8.4.18,安裝中斷退出時,先輸入:sudo apt-cache search x11-dev 得到類似以下信息:
libgl1-mesa-swx11-dev - A free implementation of the OpenGL API -- development files libx11-dev - X11 client-side library (development headers) libghc6-x11-dev - Haskell X11 binding for GHC
libgtkglextmm-x11-dev - C++ wrapper for the OpenGL Extension to GTK (development files) 分別安裝上面的組件(更新為最新版本,當然如果已經是最新版本的話,它會提醒),命令如下:
sudo apt-get install libx11-dev
sudo apt-get install libgl1-mesa-swx11-dev sudo apt-get install libghc6-x11-dev
sudo apt-get install libgtkglextmm-x11-dev
4. 出錯處理
1) 剛開始安裝時顯示gcc can't create executables之類的提示 解決方案:
這是由于我用的是Ubuntu免費郵寄的安裝盤,安裝后的系統中gcc是不能用來的開發的,只有一個空殼,所以需要重新安裝gcc。 先用命令: sudo apt-get remove gcc
然后sudo apt -get install build-essential 便成功解決問題。
2) 再次安裝NS2時發現安裝至tk8.4.13時出現錯誤,安裝中斷退出。在安裝日志上發現一句:x11/xlib.h nosuch file or directory 在網上查閱了資料,原來是x11M沒有裝。 解決方案:
先安裝X11,命令為 sudo apt-get install libx11-dev 注意:apt-get之間沒有空格 結果仍然出錯如下:
checking for main in -lXbsd... no
checking for socket in -lsocket... no
checking for gethostbyname in -lnsl... yes checking for dcgettext in -lintl... no
checking for getnodebyname in -ldnet_stub... no checking that g++ can handle -O2... no checking standard STL is available... no checking for tcl.h... -I../include checking for tclInt.h... -I../include checking for libtcl8.4... -L../lib
-ltcl8.4 checking for init.tcl... ../lib/tcl8.4
checking for http.tcl... ../lib/tcl8.4/http1.0 checking Tcl http.tcl library... yes checking for tclsh8.4.11... no
checking for tclsh8.4... ../bin/tclsh8.4 checking for tk.h... -I../include
checking for libtk8.4... -L../lib -ltk8.4 checking for tk.tcl... ../lib/tk8.4 checking for X11 header files can't find X includes
otcl-1.12 configuration failed! Exiting ...
Please check http://www./nsnam/ns/ns-problems.html for common problems and bug fixes.
還是沒有得到解決.分析了一下可能是x11沒有安裝完整,于是先輸入:sudo apt-cache search x11-dev
得到以下信息:
libx11-dev - X11 client-side library (development headers)
xlibs-dev - X Window System client library development files transitional package libghc6-x11-dev - Haskell X11 binding for GHC
libooc-x11-dev - X11 specific modules for the oo2c compiler (devel)
libg l1-mesa-swx11-dev - A free implementation of the OpenGL API -- development support files
分別安裝上面的組件,命令如下: sudo apt-get install libx11-dev sudo apt-get install xlibs-dev
sudo apt-get install libghc6-x11-dev sudo apt-get install libooc-x11-dev 然后繼續安裝,等了半天,安裝完成!
3) 問題三:can't find X includes checking for X11 header files can't find X includes
otcl-1.13 configuration failed! Exiting ...
Please check http://www./nsnam/ns/ns-problems.html for common problems and bug fixes
無奈,只得在網上搜索答案,有人說X11路徑不對,目錄"/usr/include"下找到了X11,真以為路徑不對,
按照其提供的解決方法,進入有configure的文件先運行./configure --x-includes=/usr/include/X11,重新.
/install,問題仍舊存在,然后看到一個帖子,說出現的問題主要是找不到/usr/include/X11/Intrinsic.h文件, 到/usr/include/X11下一搜索,果然沒有此文件,想必有一些東西沒裝完整,嘗試:sudo apt-get install libXt-dev此步驟做完后,重新./install,這下終于ok了!
4) 問題四:make: *** [tk3d.o] Error 1 tk8.4.18 make failed! Exiting ..
原因: The required packages are :
libx11-dev , libxmu-dev , libxmu-headers , libxt-dev , libtool
解決方法: 安裝:libx11-dev , libxmu-dev , libxmu-headers , libxt-dev , libtool
5) 問題五:make: *** [libotcl.so] 錯誤 1 otcl-1.13 make failed! Exiting ..
原因: gcc 4.0版本以前是用"ld -share"來生成共享庫的,但是到了4.0以上的版本(我的 為gcc version 4.4.1),這個命令改為"gcc -share"即可 解決方法: 把ns-allinone-2.33/otcl-1.13文件夾下的configure.in及configure中的"ld -shar ed"替換成"gcc -shared",并保存。回到ns-allinone-2.33/目錄重新運行"./install"
6) 問題六:錯誤提示:make: g++:命令未找到 make: *** [tcl2c++] 錯誤 127 tclcl-1.19 make failed! Exiting ... 在終端輸入命令 g++,看提示信息,如下 yhf@yhf-desktop:~$ g++
若顯示:程序 'g++' 已包含在以下軟件包中: * g++
* pentium-builder
試試:sudo apt-get install <選定的軟件包> bash: g++:找不到命令 yhf@yhf-desktop:~$ 說明,沒裝g++…… 若顯示 g++: 沒有輸入文件
說明,您裝了……(我還沒遇到這個問題)
那就裝一個吧,命令是 sudo apt-get install g ++ 選擇 y ,ok,等會兒吧……
我的g++裝過,只是制作交叉編譯鏈的時候,換了個低版本的……
7). 問題七[libotcl.so] 錯誤 1cd ns-2.30 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./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. 改完后重新安裝。
8). 問題八[Tcl.o] 錯誤 1
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.4和4.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.3和GCC4.4的可選項,在終端輸入以下命令
1. sudo update-alternatives --install/usr/bin/gcc gcc /usr/bin/gcc-4.4 40 2. sudo update-alternatives --install /usr/bin/gccgcc /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低版本。。。
9) 問題九:安裝成功后運行樣例程序發現ns模擬沒有問題就是不能自動調用nam! 顯示錯誤為:
ns: finish: couldn't execute "nam": no such file or directory while executing
"exec nam out.nam &"
(procedure "finish" line 7) invoked from within "finish"
解決方案:
先手動編譯nam生成可執行文件nam
進入NS_HOME/nam-1.12(NS_HOME為安裝ns2的路徑)輸入命令:make 結果顯示錯誤:
xwd.c:87:29: 錯誤: X11/Xmu/WinUtil.h:No such file or directory make: *** [xwd.o] 錯誤 1
問題是xmu沒有安裝,于是只好再裝xmu, 命令為:
sudo apt-get install libxmu-dev
然后在輸入make進行編譯,完成后在NS_HOME/nam-1.12/中可以發現可執行文件nam將其復制到 NS_
HOME/bin/目錄下,這樣由于$PATH環境變量中有NS_HOME/bin項,nam就可以直接運行了。
至此,終于大功告成了!!!
10) 問題十:安裝成功NS2后,可以運行ns命令,但是卻不能運行nam圖形界面,輸入 >nam
提示出現下列錯誤
[code omitted because of length] : no event type or button # or keysym while executing
"bind Listbox <MouseWheel> {
%W yview scroll [expr {- (%D / 120) * 4}] units }"
invoked from within
"if {[tk windowingsystem] eq "classic" || [tk windowingsystem] eq "aqua"} { bind Listbox <MouseWheel> {
%W yview scroll [expr {- (%D)}] units }
bind Li..."
由于nam調用的tk組件和xproto-7.0.13不兼容導致的(xproto-7.0.13 新添加了 GenericEvent) 可以到這里下載補丁http://bugs./show_bug.cgi?id=225999
作者的意思就是在 /ns-allinone-2.33/tk8.4.18/tk-8.4.14/generic/tkBind.c 的第588行添加: #ifdef GenericEvent
/* GenericEvent */ 0, #endif
保存退出后,$cd ns-2.33 $./install
重新安裝ns-allinone2.33就可以了.
最后,需要將ns-2.33中的“ns”和nam-1.12中的“nam”拷貝到/usr/local/bin下面。 這樣就能正常調用ns和nam了
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./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”則重新啟動試試。
|