原先是在win_cygwin下安装的,还是比较顺,基本没出问题。最近VisualBox+Ubuntu玩玩看,准备在上面安装NS2,顺便学习一下Linux。
学习需要2.31,安装有问题,没仔细看出错信息,otcl有误,鲁莽认为版本有问题,下ns2.34,目前最新,09年。估计ns3风生水起,2停止release了。
转入正题。
$ wget http://nchc.dl.sourceforge.net/sourceforge/nsnam/ns-allinone-2.34.tar.gz安装同样是在进行中,OTCL出错,退出,原因未知(“otcl-1.13 make failed! Exiting …”不知其所以然,google之)
$ tar -xzvf ns-allinone-2.34.tar.gz
$ cd ns-allinone-2.34
$ sudo apt-get install build-essential autoconf automake libxmu-dev
$ ./install
解决方法:
ns-allinone-2.34/ns-2.34中找到 Makefile.in,修改
CC = @CC@ 改为 CC = gcc-4.3
CPP = @CXX@ 改为 CPP = g++-4.3
OS中有gcc,g++ ?
$ sudo apt-get install g++-4.3
$ CC=gcc-4.3 CXX=g++-4.3 ./install
执行。。。。。。
中间没看清,./install 重新工作,安装结束, 对Linix机理还是不清楚,www.linuxidc.com惭愧!
修给环境变量:
$ gedit ~/.bashrc
末尾添加:
# LD_LIBRARY_PATH
OTCL_LIB=/your/path/ns-allinone-2.34/otcl-1.13
NS2_LIB=/your/path/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB
# TCL_LIBRARY
TCL_LIB=/your/path/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/your/path/ns-allinone-2.34/bin:/your/path/ns-allinone-2.34/tcl8.4.18/unix:/your/path/ns-allinone-2.34/tk8.4.18/unix
NS=/your/path/ns-allinone-2.34/ns-2.34/
NAM=/your/path/ns-allinone-2.34/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM
为使修改的环境变量立即生效,执行
$ source ~/.bashrc
至此ok
$ns
% 出现,证明一切彻底ok
试了一个例子通过。
转: eclipse调试ns程序
Eclipse
Open Eclipse
Set the workspace as the ns installation path( /home/username/ns-allinone-2.34 ) by selecting File -> Switch Workspace
Choose File -> New -> Project -> C++ Project
Select Project Type as Makefile Project -> Empty C++ Project.
Toolchains: Linux GCC
Enter Project Name as ns-2.34
Uncheck “Use default location” then browse to the directory NS-2 source directory ( …/ns-allione-2.34/ns-2.34 )
Select “Next” and “Finish.
From the workspace, Selecting the NS-2 Project and choosing Project -> Build All should not give Error.
Running the project must open the console with the NS-2 prompt, %
Setting Debug Configuration:
Select Run -> Debug Configurations
Choose C/C++ Application. Type in any name.
Under the Main tab, Choose the following:
Project as ns-2.34.
C/C++ Application as ns. (Search Project and Choose this)
Under the Debugger tab, choose GDB Debugger. Uncheck the “Stop on startup at” option.
Apply and Debug.