将NS2嵌入到Eclipse中进行开发运行
2013-4-18
一. 准备工作
l 安装NS2 (通进源码包进行编译安装)
l 安装Eclipse[1],我使用的是ubuntu系统。
l 安装GCC工具链,命令如下:
sudo apt-get install build-essential
二. Ubuntu(Linux)使用Eclipse搭建C/C++编译环境
l To install C/C++ development tools (CDT),from Eclipse select Help->Install New Software ( Alternate method : download from a browser.
l Click Available Software Sites and choose one site , then copy it. Click ok.
l Past the web site you have selected to the [work with:]
l Select Programming Languages
l Select C/C++ Development Tools &C/C++ Development Tools SDk
l Click Next and go on, untile you have finished successfully.
l 部分截图
一. 将NS2嵌入到Eclipse中
l Open Eclipse
l New workspace
l Choose File -> New -> Project -> C++ Project
l Select Project Type as Makefile Project -> Empty C++ Project.Toolchains: Linux GCC
l Enter Project Name as ns2
l Select “Next” and “Finish.
l Right click ns2(the project name )
l Select C/C++ General ->Paths and Symbols-> Source Location->add Folder
l Select /home/username/ns2安装文件夹
l From the workspace, Selecting the NS-2 Project and choosing Project -> Build All should not give Error.
l Running the project must open the console with the NS-2 prompt, %
二. 配置调试功能
方案一:
l cd ..../ns-allinone-2.35/ns-2.35
l sudo ./configure -enable-debug
l sudo make
方案二:
l Open .../ns-allinone-2.35/ns-2.35/Makefile.in
l Add these lines anywhere near the top of the file
CCOPT = -g # Hinzufügen der "-g"-Option
DEFINE = -DNDEBUG # Löschen des NoDebug-Flags
DEFINE = -DDEBUG # Hinzufügen des Debug-Flags
l run sudo ./configure
l Run ”./make clean” ”./make depend” ”./make”
三. 设置eclipse中的debug
l Select Run -> Debug Configurations
l Choose C/C++ Application. Type in any name.
l Under the Main tab, Choose the following:Project as ns-2
l C/C++ Application as bin/ns
l Under the Debugger tab, choose GDB Debugger. Uncheck the “Stop on startup at” option
l Apply and Debug
四. 增加tcl运行功能
l NS有两种运行方式,
运行方式一:在终端中直接输入ns,会出现%提示符,在该提示符下可输入NS命令。上一步所示属于这种方式。
运行方式二:增加tcl运行功能这需要设 置。进入Properties for New configuration框,点击Arguments, 在其中的program arguments框中输入example1.tcl并保存即可。
注意,此时,example1.tcl应处于项目目录下,否则输入tcl 文件的完整目录。例如:
/home/ubuntu/ns-allinone-2.35/ns-2.35/tcl/ex/example.tcl
五. 参考文献
1. Install Eclipse & Ubuntu(Linux)使用Eclipse搭建C/C++编译环境 http://www.lvr.com/eclipse2.htm
2. 将NS2嵌入到Eclipse中 http://www.baisi.net/thread-3039994-1-2.html
3. NS2 for Eclipse http://blog.csdn.net/king_far/article/details/5935409
4. Ubuntu 12.04 使用Eclipse搭建C/C++编译环境 http://blog.sina.com.cn/s/blog_93dc666c01019xft.html