Show
Eclipse 4.3 (Kepler) for C/C++ ProgrammingHow To Install Eclipse CDT 8.2 and Get StartedEclipse is an open-source Integrated Development Environment (IDE) supported by IBM. The mother site is @ www.eclipse.org. Eclipse is popular for Java project development. It also supports C/C++, PHP, Python, Perl, and other web project developments via extensible plug-ins. Eclipse is cross-platform and runs under Windows, Linux and Mac OS. How to Install Eclipse C/C++ Development Tool (CDT) 8.1.2 for Eclipse 4.2.2 (Juno)Step 0: Install MinGW GCC or Cygwin GCCTo use Eclipse for C/C++ programming, you need a C/C++ compiler. On Windows, you could install either MinGW GCC or Cygwin GCC. Choose MinGW if you are not sure, because MinGW is lighter and easier to install, but having less features.
Step 1: Install Eclipse C/C++ Development Tool (CDT)Two ways to install CDT, depending on whether you have previously installed an Eclipse:
Step 2: ConfigurationYou do NOT need to do any configuration,
as long as the Cygwin or MinGW binaries are included in the Writing your First C/C++ Program in EclipseC++ ProgramStep 0: Launch Eclipse
Step 1: Create a new C++ ProjectFor each C++ application, you need to create a project to keep all the source codes, object files, executable files, and relevant resources. To create a new C++ project:
Step 2: Write a Hello-world C++ Program
If "Unresolved Inclusion Error"If error "unresolved inclusion" appears next to For Cygwin GCC:
For MinGW GCC:
NOTE: To find the header paths, you can do a search on headers such as " Note: If you encounter "error while loading shared libraries" during link. Install " Step 3: Compile/BuildRight-click on the " Step 4: RunTo run the program, right-click on the " NOTE: You need to create a new C++ project for EACH of your programming problems. This is messy for writing toy programs! C ProgramFollow the same steps as above. Create a "C Project" (instead of "C++ Project"). Try the following Hello-world program (called " #include <stdio.h> int main() { printf("Hello, world!\n"); return 0; } C++ Program with MakefileIn the previous examples, we use so-called managed-make where Eclipse automatically generated a makefile to build the program. We can also choose to write our own makefile for complete control of the building process. Step 1: Create a C++ Makefile ProjectFrom "File" menu ⇒ New ⇒ Project... ⇒ C/C++ ⇒ C++ project ⇒ In "Project name", enter " Step 2: Write a C++ ProgramRight-click on the project ⇒ New ⇒ Source File ⇒ In "Source file", enter " #include <iostream> using namespace std; int main() { cout << "Hello, world!" << endl; return 0; } Step 3: Write a MakefileRight-click on the project ⇒ New ⇒ File ⇒ In "File name", enter " all: Hello.exe clean: rm Hello.o Hello.exe Hello.exe: Hello.o g++ -g -o Hello.exe Hello.o Hello.o: Hello.cpp g++ -c -g Hello.cpp Step 4: Build the ProjectRight-click on the project ⇒ Build Project. Step 5: Run the ProgramRight-click on the project ⇒ Run As ⇒ Local C/C++ Application. [TODO] Write a makefile to compile toy-programs under one project. Read the DocumentationAt a minimum, you SHOULD browse through Eclipse's "Workbench User Guide" and "C/C++ Development User Guide" - accessible via the Eclipse's "Welcome" page or "Help" menu. This will save you many agonizing hours trying to figure out how to do some things later. Debugging C/C++ Programs in Eclipse CDTAble to use a graphics debugger to debug program is crucial in programming. It could save you countless of hours guessing on what went wrong. Step 0: Write a C++ Program - The following program computes and prints the factorial of
The Factorial of 20 is -2102132736 Let us use the graphic debugger to debug the program. Step 1: Set an Initial Breakpoint - A breakpoint suspends program execution for you to examine the internal states (e.g., value of variables) of the program. Before starting the debugger, you need to set at least one breakpoint to
suspend the execution inside the program. Set a breakpoint at Step 2: Start Debugger - Right click on the project (or use the "Run" menu) ⇒ "Debug As" ⇒
"Local C/C++ Application" ⇒ choose "Yes" to switch into "Debug" perspective (A perspective is a particular arrangement of panels to suits a certain development task such as editing or debugging). The program begins execution but suspends its operation at the breakpoint, i.e., the As illustrated in the following diagram, the highlighted line (also pointed to by a blue arrow) indicates the statement to be executed in the next step. Step 3: Step-Over and Watch the Variables and Outputs - Click the "Step Over" button (or select "Step Over" from "Run" menu) to single-step thru your program. At each of the step, examine the value of the variables (in the "Variable" panel) and the outputs produced by your program (in the "Console" Panel), if any. You can also place your cursor at any variable to inspect the content of the variable. Single-stepping thru the program and watching the values of internal variables and the outputs produced is the ultimate mean in debugging programs - because it is exactly how the computer runs your program! Step 4: Breakpoint, Run-To-Line, Resume and Terminate - As mentioned, a breakpoint suspends program execution and let you examine the internal states of the program. To set a breakpoint on a particular statement, double-click the left-margin of that line (or select "Toggle Breakpoint" from "Run" menu). "Resume" continues the program execution, up to the next breakpoint, or till the end of the program. "Single-step" thru a loop with a large count is time-consuming. You could set a breakpoint at the statement immediately outside the loop (e.g., Line 12 of the above program), and issue "Resume" to complete the loop. Alternatively, you can place the cursor on a particular statement, and issue "Run-To-Line" from the "Run" menu to continue execution up to the line. "Terminate" ends the debugging session. Always terminate your current debugging session using "Terminate" or "Resume" till the end of the program. Step 5: Switching Back to C/C++ perspective - Click the "C/C++" perspective icon on the upper-right corner to switch back to the "C/C++" perspective for further programming (or "Window" menu ⇒ Open Perspective ⇒ C/C++). I can's stress more that mastering the use of debugger is crucial in programming. Explore the features provided by the debuggers. Other Debugger's FeaturesModify the Value of a Variable: You can modify the value of a variable by entering a new value in the "Variable" panel. This is handy for temporarily modifying the behavior of a program, without changing the source code. Step-Into and Step-Return: To debug a function, you need to use "Step-Into" to step into the first statement of the method. You could use "Step-Return" to return back to the caller, anywhere within the method. Alternatively, you could set a breakpoint inside a method. NOTE: If you receive error message "Can't find a source file at Tips & TricksRead Eclipse for Java's Tips & Tricks for general tips in using Eclipse. C/C++ Software Development Using GCC
File I/O in EclipseRefer to Eclipse for Java's File IO. REFERENCES & RESOURCES
Latest version tested: Eclipse 4.2.2 (Juno), Eclipse CDT 8.1.2 What C programming keyword is used to define a structure?'struct' keyword is used to create a structure.
What is the global variable that indicates an error occurred during any function call defined in error H header file?errno. A global variable that indicates an error occurred during any function call.
What does a storage class define regarding variables quizlet?The register storage class is used to define variables that should be stored in a register instead of RAM. - is used on a global variable, it causes only one copy of that member to be shared by all the objects of its class.
|