Using Eclipse to debug ns-2 c++ code is very useful. Karthik Sankar has made a very good walkthrough for setting this up: http://blog.karthiksankar.com/ns2-eclipse/ However, I encountered some problems when following the walkthrough. Therefore, I repeat the walkthrough with the needed changes here. This solution should work with newer versions of ns-2 (i.e. 31-35) and Eclipse Indigo in Linux.
Setting up Eclipse:
Download Eclipse SDK
Extract the SDK to a folder
Go to Help -> Install New Software. In the Work With bar type this:
Choose CDT Main Features and CDT Optional Features. Install them.
CDT stands for “C/C++ Development Tooling”
If you do not have a working internet connection in the system you have installed Eclipse, instead of steps 4 and 5, download the CDT from the above mentioned site. Then move to Install New Software (see step 4) -> Add and add the archive downloaded.
Extract NS-2 to a folder, i.e. /home/username/ns-allinone-2.34
Open “…/ns-allinone-2.34/ns-2.34/Makefile.in” and
Add -g to the line CCOPT = @V_CCOPT@ as follows
CCOPT = @V_CCOPT@ -g
Add -DNDEBUG -DDEBUG to the end of the following line:
DEFINE = -DTCP_DELAY_BIND_ALL -DNO_TK @V_DEFINE@ @V_DEFINES@ @DEFS@-DNS_DIFFUSION -DSMAC_NO_SYNC -DCPP_NAMESPACE=@CPP_NAMESPACE@-DUSE_SINGLE_ADDRESS_SPACE -Drng_test -DNDEBUG -DDEBUG
Navigate to …/ns-allinone-2.34/ns-2.34 and run “./configure”
Navigate to the NS-2 folder using terminal and type ./install
Also, follow the instructions are displayed at the end of a successful installation. These instructions are to modify the PATH variable and other environment variables as needed.
You may encounter compilation troubles, due to the DEBUG flag being enabled. My experience was that several printf statements needed to be disabled (commented out):
mobile/shadowing-vis.cc line 293
aodv/aodv.cc line 210
aomdv/aomdv_rtable.cc line 186
aomdv/aomdv.cc line 283
Adding NS-2 as a Project in 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 )
In Eclipse Indigo, you may not be allowed to create a new project in the existing ns-2.34 subfolder if you uncheck the “Use default location” checkbox. You will not need to, anyway, if you have chosen the parent folder as workspace. In this case, Eclipse will only warn you that you are creating a project in a directory which already exists.
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.