"NS2" with Eclipse Debug NS2 (reprint)

Source: Internet
Author: User

I believe that many people who like Java have a passion for eclipse. NS2 program debugging, you can use the Print command debugging, this is too cumbersome. can also use GDB debugging, personally feel more difficult to get started. I believe that you learn NS2 novice, when looking at the code, a lot of functions or variables, do not know where to declare, will be in the program to start using, often make us very confused.

Debugging and reading the code, let eclipse help you solve it.

1. Download Eclipse and install the CDT plugin. The CDT plugin allows eclipse to create C, C + + engineering. When downloading the CDT plugin, be careful to match the Clipse version. Of course you can also go to Eclipse's official website and download a version of Eclipse specifically developed for C and C + +. This will not install the CDT plugin.

2, after installing NS, and can not debug NS, because at the time of installation of the compile link operation did not add debugging information to the executable NS, the NS file at this time only 5 m multi-size. To debug NS, you need to add debugging information to the NS file, which will modify the makefile file to include the GCC command-G option, but this does not require manual modification, as follows:

Enter the ns-allinone-2.27./ns2.27 directory and execute the command
./configure--enable-debug
This action generates a new makefile, and looking at the compile command in the new makefile file will find that the-G option is added. The NS file with the debug information added is 15M in size

3. In Eclipse, select Makefile Project, C + + project, File, New, project. Fill in the project name NS-2.27. Use the Default location to remove the tick. The location is then set to the directory NS2.27 where makefile resides. Select Cygwin GCC in the toolchains. then click Finish.

4. When you're done, you can check out the Eclipse console console, which displays information about the NS2 of Eclipse compilation in madness. Seems to be in make.

5. If unfortunately, 3 errors occurred after Eclipse compilation, the first error is about finding NAMESPACE cpp_namespace, second, third .... The following teaches you to fix this error, enter the NS2 2.27 directory and open the Autoconf.h file. Replace the following:

/* STL */
#ifdef __cplusplus
#define HAVE_STL 1

#define CPP_REQUIRES_NAMESPACE 1
#ifdef Cpp_requires_namespace
using namespace Cpp_namespace;
#endif/* Cpp_namespace */
#endif/* __cplusplus */

To be replaced by:

/* STL */
#ifdef __cplusplus
#define HAVE_STL 1
#define CPP_NAMESPACE STD

#define CPP_REQUIRES_NAMESPACE 1
#ifdef Cpp_requires_namespace
using namespace Cpp_namespace;
#endif/* Cpp_namespace */
#endif/* __cplusplus */

6. Re-make in Cygwin window. Right--built Configuration-build-all on NS2 project in Eclipse. This time really is done, if still problem, I also did not encounter, solve it myself.

Then when you look at NS2 C + + code, if you want to see which variable or method definition, it can be easily found through eclipse. Note the use of the F3 button yo ~ ~ ~

It is said that the eclipse-shaped interface is much easier to debug than debugging directly with GDB.

Finally: If you do not take the Tcl file as a parameter to run, if the console input puts "Hello world" and other commands do not execute correctly, in the run configuration to set a path path, point to the Cygwin bin directory. Then you can run it. Good luck ~ ~ ~

"NS2" with Eclipse Debug NS2 (reprint)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.