Working with Projects
Project in Eclipse is a fundamental unit of compilation and
execution. The project has to be created, then a source file (or
files) needs to be added to it. The project then needs to be compiled,
debugged. A successfully compiled project is run (executed).
Creating a C++ project:
If the current perspective is not C/C++, click Window >
Open Perspective > Other... and select C/C++ from the list of
possible perspectives.
On the main menu bar click File > New > C++ Project.
A window for creating a new C++ Project opens.
In the Project name field, type the name of the new project.
To specify a different directory in which to save your project,
clear the Use Default Location check box, and enter the path in
the Location box.
Select Executable as the Project type in the left
pane. This provides an executable application. Note that the
Executable project type folder contains three templates. Usually you
will want to select Empty Project.
- Hello World C++ Example provides a simple C++ Hello World application with main().
- Hello World ANSI C Example provides a simple C Hello World application with main().
- Empty Project provides a single source project folder that contains no files.
Select Cygwin GCC as the Toolchain in the right pane.
To create your project, click Finish.
Your new project displays in the Project Explorer View. The new
project does not contain any source files.
Tip: You can view and modify the properties of your project by
right-clicking on the project in the C/C++ Projects view and clicking
Properties.
Adding a Source File to the Project
- In the project explorer view, right-click on the name of the project to add the file to.
- From the dropdown menu select New --> Source File
- In the dialog box that appears, type in the file name. Do not forget to add file name extension. For C++ programs the extension is .cpp
- For the template select either < None> or Default C++ source template
- Click Finish
The new file should appear under the project name in the project
explorer view. The file also opens in the editor view for editing.
Building the Project
After the source file is entered, the project source files need to be compiled into executable. To build a project:
- select the project in the project explorer view
- in the pull-down menu select Project --> Build All. A
shortcut for this option is a hammer icon on the toolbar
or Ctrl+B keystroke.
The console view displays the output of the project compilation.
There can be several outcomes:
Note: If a build generates any errors or warnings, you can see those in the Problems view.
Running the Project
A Successfully compiled project can be run (executed). To run the project:
- select the project in the project explorer view
- in the pull-down menu select Run --> Run As --> Local C/C++ Application .
A shortcut for this option is a run (green circle with a triangle) icon on the toolbar or
Ctrl+F11 keystroke.
The console view will display the output and take user input for the program as it runs.