Ubuntu 10.04 下 安裝 NS2.30 1. NS2下載 在OpenSource中search 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*)’: 由於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/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++ 得到結果:
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" 還得運行一個命令,爲source .bashrc
6. 安裝驗證 安裝結束後的提示中也告訴我們如何驗證是否正確安裝: cdns-2.30 ./validate 另外,也可以打開一個新終端進行試運行: 輸入ns,如果顯示一個%則說明已正確安裝。如果提示“command not found”則重新啓動試試。 |
安裝NS-2.28全過程一(包括所有可能遇到的問題)
安裝包是ns-allinone-2.28.tar.gz。Ubuntu7.10內核是2.6.22-14.
首先sudo apt-get update
sudo apt-get install build-essential 這是更新ubuntu
sudo apt-get install tcl8.4 tcl8.4-dev tk8.4 tk8.4-dev 這是爲安裝NS做準備
sudo apt-get install libxmu-dev libxmu-headers 安裝nam做準備
解壓縮後,
輸入:cd ns-allinone-2.28
輸入:ls -a
回車後就可以看到一個名字爲install的文件.
然後在終端中輸入:./install
OK,NS開始安裝了
然後waiting……
出現問題及解決方法
問題1
checking system version (for dynamic loading)... ./configure: 1: Syntax error: Unterminated quoted string
tcl8.3.2 configuration failed! Exiting ...
Tcl is not part of the ns project. Please see www.Scriptics.com
to see if they have a fix for your platform.
解決方法
分別進入以下目錄:tcl8.x.x/unix/tcl.m4.
tk8.x.x/unix/tcl.m4.
otcl-1.x/configure.in.
將這些文件裏的system=MP-RAS-`awk ' { print $3 } '/tc/.relid'` 改爲:
system=MP-RAS-`awk ' { print $3 } '/etc/.relid`
然後再在這三個目錄下運行命令autoconf.每個目錄下運行兩次~
問題2
繼續輸入 ./install
./sctp/sctp.h:630: error: extra qualification ‘SctpAgent::’on member ‘DumpSendBuffer’ make: *** [trace/trace.o] Error 1
Ns make failed!
解決辦法
將文件sctp.h裏面第630行DumpSendBuffer函數前面的'SctpAgent::'去掉。
問題3
繼續輸入 ./install
./mobile/god.h:88: error: extra qualification ‘vector::’ on member ‘operator=’
./mobile/god.h:93: error: extra qualification ‘vector::’ on member ‘operator+=’
./mobile/god.h:98: error: extra qualification ‘vector::’ on member ‘operator==
./mobile/god.h:101: error: extra qualification ‘vector::’ on member ‘operator!=’
make: *** [src_rtg/sragent.o] Error 1
Ns make failed!
解決辦法:
分別將這些文件裏面的‘vector::'去掉。
問題 4
queue/cbq.cc:112: error: ISO C++ forbids declaration of ‘CBQueue’ with no type
queue/cbq.cc:112: error: expected ‘;’ before ‘*’ token
queue/cbq.cc: In member function ‘virtual int CBQueue::insert_class(CBQClass*)’:
queue/cbq.cc:488: error: ‘class CBQClass’ has no member named ‘cbq_’
queue/cbq.cc: In constructor ‘CBQClass::CBQClass()’:
queue/cbq.cc:805: error: class ‘CBQClass’ does not have any field named ‘cbq_’
queue/cbq.cc: In member function ‘virtual void CBQClass::recv(Packet*, Handler*)’:
queue/cbq.cc:850: error: ‘cbq_’ was not declared in this scope
queue/cbq.cc:856: error: ‘cbq_’ was not declared in this scope
queue/cbq.cc: In member function ‘void CBQClass::update(Packet*, double)’:
queue/cbq.cc:873: error: ‘cbq_’ was not declared in this scope
queue/cbq.cc: In member function ‘int CBQClass::desc_with_demand()’:
queue/cbq.cc:928: error: ‘cbq_’ was not declared in this scope
queue/cbq.cc: In member function ‘void CBQClass::newallot(double)’:
queue/cbq.cc:975: error: ‘cbq_’ was not declared in this scope
queue/cbq.cc: In member function ‘virtual int CBQClass::command(int, const char* const*)’:
queue/cbq.cc:1002: error: ‘cbq_’ was not declared in this scope
make: *** [queue/cbq.o] Error 1
Ns make failed!
解決辦法
用補丁——
補丁的用法即找到相應文件後,找到相應的程序段,行列數爲@@ ...... @@之間數字,手動把補丁程序段中前面帶有“+”號的行添加到文件中,而將前面帶有“-”號的行在文件中刪除,這是很花費時間的一件事,要有耐心~~
(網上很多類似的補丁,但很少類似的補丁用法說明。我自己在這裏也浪費了很多時間,後來慢慢摸索出來的,爲了看明白還去找了些patch的說明來看,後來還是一個同學說的好,patch爲後綴的補丁包其實是註明了在哪個文件中的什麼地方添加什麼程序段,減少什麼程序段)
用如下補丁
--- cbq.cc.old 2006-08-31 11:42:09.000000000 -0300
+++ cbq.cc 2006-08-31 11:43:31.000000000 -0300
@@ -87,6 +87,8 @@
#define LEAF_LEVEL 1 /* level# for leaves *
#define POWEROFTWO 16
+class CBQueue;
+
class CBQClass : public Connector {
public:
friend class CBQueue;
問題5
./tora/tora_neighbor.h:72: error: ISO C++ forbids declaration of ‘toraAgent’ with no type
./tora/tora_neighbor.h:72: error: expected ‘;’ before ‘*’ token
make: *** [tora/tora.o] Error 1
Ns make failed!
解決辦法:
用如下補丁——
--- tora_neighbor.h.old 2006-08-31 11:57:34.000000000 -0300
+++ tora_neighbor.h 2006-08-31 11:58:11.000000000 -0300
@@ -41,6 +41,8 @@
#ifndef __tora_neighbor_h__
#define __tora_neighbor_h__
+class toraAgent;
+
enum LinkStatus {
LINK_UP = 0x0001, // upstream
LINK_DN = 0x0002, // downstream
問題6
dsr/dsragent.cc: In member function ‘void DSRAgent::handleFlowForwarding(SRPacket&, int)’:
dsr/dsragent.cc:804: error: ‘XmitFlowFailureCallback’ was not declared in this scope
dsr/dsragent.cc: In member function ‘void DSRAgent::sendOutPacketWithRoute(SRPacket&, bool, Time)’:
dsr/dsragent.cc:1361: error: ‘XmitFailureCallback’ was not declared in this scope
dsr/dsragent.cc:1362: error: ‘XmitFlowFailureCallback’ was not declared in this scope
dsr/dsragent.cc:1379: error: ‘XmitFailureCallback’ was not declared in this scope
make: *** [dsr/dsragent.o] Error 1
Ns make failed!
解決辦法
打開 dsr/dsragent.cc 搜索XmitFlowFailureCallback和XmitFailureCallback,發現除了828、1385、1386、1403行之外,在文件後面還有這兩個函數聲明,把這兩個函數聲明移到文件前面