4 The Eclipse IDE in a nutshell – Computational Technologies

Petr N. Vabishchevich

4 The Eclipse IDE in a nutshell

Abstract: The Eclipse12 Integrated Development Environment (IDE) is widely used to develop cross-platform software written in various programming languages. In this chapter, we study the main features of Eclipse: project management, code editing, compiling, debugging, and linking.

4.1 The Eclipse architecture and GUI

The basic features of Eclipse, its installation, and the various plug-ins are breafly considered below.

4.1.1 Integrated development environments

An integrated development environment is a unified system intended for software development. It is designed to quickly create high-quality software (using efficient tools for development and automation) under the best possible conditions (using a convenient graphic user interface (GUI)).

Of course, we can use the command line, write a program in a simple text editor, and debug it using command-line tools. Moreover, some users may like this, but most users prefer to employ IDEs.

Modern IDEs fully resolve various problems in designing software and include a great number of separate components. This results in a certain inconvenience in using development tools and complicates the study and usage of their features.

Therefore, we can begin with some text editor with advanced features which simplify coding. Such editors provide, for example, syntax highlighting and autocompletion, as well as running of the compiler and debugger.

Integrated development environments provide significantly greater convenience and integration in software development. There are a lot of such frameworks for c/c++ programming. The reader can find a long list of these at http://en.wikipedia.org/wiki/Comparison_of_integrated_development_environments.

4.1.2 Free cross-platform IDEs

Among existing IDEs, we omit proprietary software (private, commercial). Therefore, our choice is free software (free for use, copying, distribution, and change).

The second requirement is portability of applications, i.e. we need to work simultaneously on Linux and windows operating systems. From this point of view, we will not consider the contribution of Microsoft to the development of free IDEs such as Microsoft Visual Studio Express13, which is positioned as an IDE for beginners. We also do not consider e.g. the Anjuta IDE14, which supports a number of of programming languages (C, C++, Vala, Java, JavaScript, Python), but works only under Linux.

Among cross-platform IDEs, we should mention Code: :Blocks15. This IDE supports GCC compilers as well as GNU GDB. The editor provides syntax highlighting, autocompletion of text, etc. Like other more powerful IDEs, the functionality of Code: : Blocks expands by plug-ins.

Geany16 is positioned as a simple, fast, and compact development environment. It recognizes and highlights the syntax of many programming languages (more than 40) includig, of course, C/C++. Geany supports project management, autocompilation, and execution. This functionality can also be expanded via plug-ins.

A more powerful free IDE, namely, NetBeans IDE17, is written in Java. For this, the Java Virtual Machine (Oracle JDK or an appropriate version of OpenJDK) must be preinstalled in order to employ NetBeans IDE. This IDE is initially focused on the development of applications in Java. Other programming languages (e.g. C/C++, PHP) are supported using plug-ins. However, the user can install a separate IDE installation for the development of C/C++ applications. In particular, NetBeans IDE supports refactoring and profiling tools, as well as visual debugger and a collection of predefined code templates.

The cross-platform library Qt18 is often used to develop C++ applications with a graphical user interface. The features of this library are most easily applied in the Qt Creator IDE. In addition to the standard tools for code writing and debugging applications, Qt creator is integrated with the visual Qt Designer GUI and the help system Qt Assistant. The Qt Linguist tool, which simplifies the localization and translation of applications into other languages, should also be mentioned.

It seems reasonable to apply codeLite19 for the development of cross-platform applications with GUI on the basis of the wxWidgets library. This is a free IDE for the C/C++ languages. Project management, autocompletition, refactoring, syntax highlighting, and interactive debugger are also supported in this IDE.

4.1.3 Eclipse

Many developers of cross-platform applications use the free Eclipse20 IDE. In many companies, Eclipse is considered to be the corporate standard of IDE for development in various programming languages.

Eclipse is written in Java and is a platform-independent software. Some users use Eclipse as IDE for the development of applications in Java with the standard tools to work with projects, editor, and debugger. Actually, Eclipse is a general framework for the integration of development tools for working with various types of applications. It is positioned as an extensible platform to develop and support applications throughout their entire life-cycle, i.e. from writing code to supplying updates.

As the platform for various applications, the standard release of Eclipse contains plug-ins which support Java (JDT, Java Development Tools) and allow development of other plug-ins (PDE, Plug-in Development Environment). The user who wants to work with other languages will nees to install special plug-ins. For the most popular languages, istallation packages with built-in plug-ins for the selected language are available.

The extensibility of Eclipse is provided by a set of utilities which are installed as plug-ins. We can select, for example, a preferred system for controling versions as well as various plug-ins for the source code analysis. Thus, using Eclipse we can write codes in any programming language, use any plug-ins, and work on any platform.

The Eclipse CDT21 C/C++ Development Tools, the full functionality C/C++ IDE, is built on the basis of the Eclipse platform.

4.1.4 Installation

On the Eclipse download page22, we can select the Eclipse IDE for C/C++ installation package for a specified operating system.

Developers using Linux will be interested in the Eclipse IDE for C/C++ Linux Developers. It additionally includes plug-ins for debugging: GCov, GProf, OProfile and Valgrind.

To run Eclipse, we need the Java Virtual Machine (JVM) to be preinstalled. The version of the installed Java Runtime Environment (JRE) is checked by the command

To install JRE, the following command

is employed.

The installation of Eclipse finishes with decompression of the archive into a given directory. The program is invoked by the eclipse command (an executable file) in the program’s directory.

The first launch of Eclipse opens a window for selecting workspace, as shown in Figure 4.1. The workspace is a directory for the user’s projects. The user can employ the workspace given by default; then this box will no longer appear. To change the workspace, the File | Switch Workspace menu command is applied.

Fig. 4.1. Eclipse workspace launcher.

After selecting workspace, the welcome page is displayed (see Figure 4.2). By clicking on one of the buttons, we can go to the page containing

  • – Overview – links to online resources teaching to Eclipse;
  • – Tutorials – examples of creating the simplest applications in C/C++;
  • – Samples – pre-installed examples; item What is new – links to an overview of new features;
  • – Workbench – the desktop development environment.

Fig. 4.2. Welcome page.

To start work, we need to click the Workbench button. The workbench does not contain any projects (see Figure 4.3).

4.1.5 Updating and installing plug-ins

To update Eclipse, we use the Help |Check for Updates menu command.

To install new plug-ins, the Help | Install New Software menu command (see Figure 4.4) is invoked by selecting a site, from which you want to install the new plug-ins. To add a new site into a list of updates, click the Add button and enter the corresponding address of the site.

We can address to the unified repository with Eclipse plug-ins, i.e. Eclipse Marketplace23. Eclipse supports work with this repository and makes it easy to search, select, install, and update plug-ins. Using the Help | Eclipse Marketplace menu command, the Eclipse Marketplace dialog is opened, as shown in Figure 4.5.

Fig. 4.3. Workspace for the first launch.

Fig. 4.4. Selection of plug-ins for installation.

Fig. 4.5. Eclipse Marketplace.

For instance, it is convenient to represent the results of calculations in the form of graphs, which can be stored as files in a particular graphical format. To visualize such data directly in Eclipse, the QuickImage utility for viewing images is useful. It supports the .gif, .jpg, .jpeg, .png,. bmp, and . ico formats and can be installed from Eclipse Marketplace.

We can get answers to many questions in the advanced Eclipse help system. For example, the help for all integrated plug-ins (see Figure 4.6) is obtained using the Help | Help Contents menu command. In particular, the help on the Eclipse development platform itself is available.

Fig. 4.6. Help for Eclipse.

4.2 Working with projects

This section analyzes the creation, compilation, and linking of C/C++ projects in Eclipse.

4.2.1 Available tools

The working tools are the basic Eclipse’s modules; they provide the work with projects and help. To resolve special problems, a set of modules is added by activating the corresponding plug-ins.

A defined kit of tools designed to solve specific problems and located in the Eclipse Workbench is called perspective (layout). Only one perspective can be active at the same time. It is possible to switch perspectives using the window | open Perspective menu command or the corresponding button in the toolbar. Using perspectives, we can create our own workbench oriented to a certain type of tasks, which takes into account our preferences in both functionality and interface.

Most perspectives consist of the editor area and one or several views. An editor is a tool which allows us to create/open, edit, and save files. In Eclipse, different editors can be linked and applied to various types of files. Views supplement the editors and display information about the file we are editing. The window | show view menu command is used to open the corresponding view.

4.2.2 Test project

The work with a project in Eclipse is illustrated by solving via the finite difference method the following boundary value problem:

We apply a uniform mesh. To check the accuracy, we consider the exact solution

To solve a system of equations with a tri-diagonal matrix, the sol function is employed. The source codes, which are contained in the files prog. cpp, prog . h, are given below. These two file are ready to use; we write in the Eclipse editor only the main program.

Listing 4.1.

Listing 4.2.

We write the main. cpp file of the program for solving the boundary value problem by means of Eclipse:

Listing 4.3.

Thus, the project consists of three files: main. cpp, prog . cpp, and prog . h.

4.2.3 Creating a project

A project is a folder that contains source codes along with compiling and linking results. Let us now create a new project with the name test. To do this, we use the File | New | C++ Project menu command (the New button with a drop-down list in the toolbar). In the C++ project wizard, which is shown in Figure 4.7, we set the name and type of our project (in our case, Empty Project without files) and select the Linux GCC toolchain. Next, we use the default settings and click the Finish button. The test project will appear in the Project Explorer view.

Fig. 4.7. New project.

Now we create the empty file main. cpp. To do this, in the Project Explorer view, we right-click on the name of our project and select New | File in the context menu (see Figure 4.8).

Next, we need to add the existing files prog. cpp and prog. h to the project. For this we use the Import Wizard that is invoked from the context menu of the project in the Project Explorer; we search for the necessary files in File System (see Figure 4.9). Further, we select the folder and the importing files (see Figure 4.10). The result is shown in Figure 4.11.

The general settings of the Eclipse platform can be edited in the Preferences dialog (the Widow | Preferences menu command). The general settings of the development environment are grouped in the General section, settings for C/C++ development are contained in the C/C++ section, and settings for the help system are grouped in the Help section, the Install /Update section contains settings for updating/auto-updating the Eclipse development platform.

Fig. 4.8. New file.

Fig. 4.9. Select files into the project.

Fig. 4.10. Importing files.

Fig. 4.11. The test project.

Project settings are available in the context menu Properties of the project. In particular, we can obtain the information about compiling and linking commands as shown in Figure 4.12.

Fig. 4.12. Project parameters.

4.2.4 Compiling, linking, and running applications

The C/C++ perspective has various views which help to develop C/C++ applications. Figure 4.11 demonstrates these views. To add a new view, we use the view show dialog invoked by the widow | show View | other menu command. To reset the current views of perspective to the default state, we apply the window | Reset Perspective command.

The common views used in the C/C++ perspective are as follows:

  • – Project Explorer: shows all files in your workspace folder;
  • – Editor : view to input and edit source files;
  • – outline : displays the structure of the current open file;
  • – Console: displays outputs appearing during the linking project and running application;
  • Problems: shows errors appearing during the work with project.

In Eclipse platform, the work of the C/C++ Development Toolkit (CDT) is based on including external utilites, which we have discussed above. The automation of the compiling and linking processes is implemented via make using the gcc or g++ compilers from the GCC collection, whereas GDB is applied for debugging.

Building a project is conducted using the Protect | Build Project menu command (or the Build Project context menu of the project) is used for the active configuration (Debug, by default). To change the configuration, we use the Project | Build Configuration | Set Active menu command. The Project | Clean command calls the cleaning dialog to discard the results of the previous project builds.

After linking the project, the configuration folder Debug is created in the project folder. This folder contains e.g. object and executable files, as well as the makefile file.

An executable file of a project can be invoked with various parameters, e.g. the arguments of the command line. The standard configuration of C/C++ Application for an executable file without parameters is generated during the first run of the application using the Run | Run As menu command. The generated run configuration is used in subsequent program runs; we can also apply the Run | Run menu command or the corresponding button in the toolbar.

In Eclipse, parameters required to run an application are specified in the run configuration (the Run | Run Configuration... menu command).

4.3 Editing a source code

The editor of Eclipse supports standard features of a text editor desined to write programs. Only its basic features that make working with a program’s code easier are discussed below.

4.3.1 Customizing the editor

It is possible to customize the editor as well as any tool of the Eclipse platform. For this purpose, there exists the command Widow | Preferences | C/C++ | Editor. In particular, we can change the syntax coloring for higher readability (see Figure 4.13).

Fig. 4.13. Editor preferences.

We can also customize the keyboard shortcuts using the General | Keys section in Preferences. For quick access to the list of shortcuts, we click ctrl+Shift+L (see Figure 4.14).

4.3.2 Working with text

We will not discuss in detail the standard commands for working with text, such as selecting, cutting, and copying text. They are available in the Edit menu.

Among the useful functions of the C/C++ code editor, we consider commands for working with comments in the Source menu. In particular, to transform a text block into comments (via /* ... */), we can use the Ctrl+Shift+/ shortcut or the command Source | Add Block Comment. In turn, the Ctrl+Shi ft+\or Sources | Remove Block Comment commands serve to remove this comments.

Fig. 4.14. Shortcuts.

Regarding the basic features of refactoring (changing the structure of a program without altering its functionality), we need to mention renaming. This allows us to easily rename classes, methods, and variables in all the files of a project. For this purpose, we select an object in the editor view and use the context menu command Reactor | Rename ... for renaming. The second way is to select the object in the Project Explorer and employ the corresponding command from the context menu.

In team development of software, it is necessary to adhere to a single style of programming. This makes the code more readable and understandable for all developers. Eclipse has a convenient function for code formatting, i.e. the menu command Source | Format. We can choose the formatting style or fine-tune it in the C/C++ | Code Style section of the Preferences.

The editor also supports code folding. We can fold a block of a code which occupies a large space in the editor view; this makes the code more readable. To fold method bodies, we need to click the minus icon in the left column; to unfold it, we click the plus icon. We can customize code folding in Widows | Preferences | Editor | Folding.

4.3.3 Quick insertion

The autocompletion function is realized in the Content Assist. To get help on this matter when writing code, we need to click Ctrl+Space.

For instance, if we type erro and press Ctrl+Space, then a list of possible completios appears in our code, as presented in Figure 4.15. Customization of Content Assist is conducted in the dialog window activated using the menu command Windows | Preferences | Editor | Content Assist.

Fig. 4.15. Autocompletion.

The editor also supports the feature of quick insert of code sections. For example, to write a loop, we enter for and select Ctrl+Space, and then select the required template (see Figure 4.16). The list of built-in templates is available through the command Windows | Preferences | Editor | Templates. This list can be supplemented with our templates using the New... button, which invokes the dialog New Template.

4.3.4 Searching for text

Eclipse supports searching for text through a specific file, selected files, folders, and the whole project.

The standard Find/Replace dialog (see Figure 4.17) is invoked by the command Edit | Find/Replace or by pressing Ctrl+F. If we choose the Wrap Search option, the search is performed cyclically. If it is not chosen, then the search is performed in a part of the file, depending on the cursor position and Direction (Forward or Backward, respectively).

Fig. 4.16. Working with text templates.

Fig. 4.17. Find-and-replace dialog.

Fig. 4.18. Search for files.

To search for files that contain some text, the Search dialog is invoked using the menu command Search | Search or by pressing Ctrl+H. Parameters of the search, file name patterns, and their scope are specified in the File search tab (see Figure 4.18). We can search through the whole workspace or in a set of some selected folders and files (Working Set).

To search for a selected text in the editor window, we can apply the command Search | Text. The results of the search are collected in the separate Search tab (see Figure 4.19), which has convenient buttons to navigate through the results.

4.3.5 Navigation through a code

The Navigation menu provides powerfull features for navigating. We mention breafly only some of them.

We can move to a line of a file with a specified number. The corresponding dialog is invoked by the command Navigation | Go to Line ... (Ctrl+L). In some cases, the command Navigation | Last Edit Location (Ctrl+Q) is useful for moving to the location of a recent edit. To move to the previously opened files (the history of the opened files), commands in the Navigation | Back and Navigation | Forward menus are used.

To navigate to a declaration of a function, class, or variable, we select the necessary identifier and press F3. The same result can be achieved by left-clicking the mouse while pressing Ctrl.

In Eclipse, various notes in a code are treated as annotations. For example, this may be errors in a code, the result of a search, and so on. Using the navigation icons in the toolbar of (Navigation | Next Annotation and Navigation | Previous Annotation), we can quickly navigate between annotations in the editor window.

Fig. 4.19. Results of the search.

4.4 Debugging applications

An introduction to the basic features of Eclipse in the detection and localization of errors is presented in the following. Debugging is based on the step-by-step execution of a program with breaks at some lines of the source code. Debugging in Eclipse CDT is performed using the GDB debugger.

4.4.1 Perspective for debugging

The debugger provides the step-by-step execution of a program and gives an opportunity to set breakpoints, pause, and to resume the program, and observe variables.

The debugger of Eclipse is organized as the standard set of plug-ins included in Eclipse. To open the debug perspective, we use the window | open Perspective | Debug menu command or the corresponding icons on the perspective tab. Figure 4.20 displays the Debug perspective. Switching the mode of working with an application is governed by commands of the Run | Run or Run | Debug menues.

Fig. 4.20. Debug perspective.

Editing a debug configuration is conducted using the Debug Configurations dialog, which is invoked by the command Run | Debug Configurations ... (see Figure 4.21).

Debugging a program and searching for errors, in many respects, are an art, but this does not mean that the programmer does not adhere in his work to some general rules and principles. Here we show only some basic tips and tricks for debugging.

4.4.2 Breakpoints

Debugging an application is based on, in particular, the intentional interruption using breakpoints. Using the debugger, we can examine a state of the program at the time moment of interruption. After that, the program can be completed or resumed from the point where it was terminated.

To create a breakpoint, we should select a line of the code and right-click on the left margin of the editor near the necessary line. After that, we choose Toggle Breakpoint in the context menu oruse the Run | Toggle Breakpoint menu command. Managing a list of breakpoints for a project is performed on the Breakpoints tab of the Debug perspective (see Figure 4.22).

Fig. 4.21. Debug configuration.

Fig. 4.22. Breakpoints.

The commands Run | Step Into, Run | Step Over, and Run | Step Return are used to step through a code. The line of the code that will be executed next is selected for stepping. We can use the corresponding icons in the Debug tab (see Figure 4.23). To move to the next breakpoint, the Run | Resume command is applied.

Fig. 4.23. Program trace.

4.4.3 Values of variables

The state of variables is traced during the debug process. Moving cursor over a variable indicates its value. Values of variables are displayed in the Variables tab (see Figure 4.24). We can study the corresponding variable by clicking its name in the list. Variables that were changed during the current step are highlighted.

Fig. 4.24. Variables.