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:

  1. If the current perspective is not C/C++, click Window > Open Perspective > Other... and select C/C++ from the list of possible perspectives.

  2. On the main menu bar click File > New > C++ Project.

  3. A window for creating a new C++ Project opens.

  4. In the Project name field, type the name of the new project.

  5. 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.

  6. 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.

  7. Select Cygwin GCC as the Toolchain in the right pane.

  8. 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

  1. In the project explorer view, right-click on the name of the project to add the file to.
  2. From the dropdown menu select New --> Source File
  3. 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
  4. For the template select either < None> or Default C++ source template
  5. 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: 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: The console view will display the output and take user input for the program as it runs.