Using the Eclipse Platform for C/D + + development

Source: Internet
Author: User
Tags posix

We will outline how to use the Eclipse platform in a C + + development project. Although Eclipse is primarily a Java development environment, its architecture ensures support for other programming languages. In this article, you will learn how to use the C/s + + development Toolbox (c + + development TOOLKIT,CDT), which is the best C + + toolbox available for Eclipse.

The C and C + + languages are the most popular and most widely used programming languages in the world, so it's no surprise that Eclipse platform (Eclipse Platform) provides support for C/s + + development. Because the Eclipse platform is just a framework for developer tools, it does not directly support C + +; it uses external plug-ins to provide support. This article will show you how to use cdt-for a set of plug-ins that are developed for C/D + +. The CDT project is dedicated to providing a fully functional, C + + integrated development environment (Integrated development environment,ide) for the Eclipse platform. Although the project focuses on Linux, it works in all environments that can use the GNU developer tools, including Win32 (Win 95/98/me/nt/2000/xp), QNX Neutrino, and Solaris platforms.

The CDT is an open source project implemented entirely in Java (licensed under Common public License) as a set of plugins for the Eclipse SDK platform. These plug-ins add a/C + + perspective to the Eclipse Workbench (Workbench), which is now supported by a number of views and wizards, as well as advanced editing and debugging support.

Because of its complexity, the CDT is divided into several components, which are in the form of separate plug-ins. Each component operates as an autonomous project with its own set of submitter, error categories, and mailing lists. However, all plugins are required for the CDT to work properly. The following is a complete list of CDT plugins/components:

The main CDT plugin (Primary CDT plug-in) is the "framework" CDT plugin.

The CDT feature Eclipse (CDT Feature Eclipse) is the CDT feature component (Feature Component).

The CDT core provides core models, CDOM, and core components (core Component).

The CDT UI is the core UI, view, editor, and wizard.

The CDT startup (CDT Launch) provides a startup mechanism for external tools such as compilers and debuggers.

The CDT debug core (CDT debug cores) provides debugging capabilities.

The CDT Debug UI (CDT Debug UI) provides the user interface for the CDT debug Editor, Views, and wizards.

CDT Debug mi (CDT debug mi) is an Application Connector for MI-compatible debuggers.

Now, let's look at how to use these components in a real-world application. Figure 1 shows the C + + project in Eclipse:

Figure 1. Editing a C + + project in Eclipse with the CDT plugin

  Installing and running the CDT

Before you can download and install the CDT, you must first ensure that the GNU C compiler (GNU C COMPILER,GCC) and all the accompanying tools (make, Binutil, and GDB) are available. If you are running Linux, install the development package by using the Package Manager for your distribution. On the Windows platform, you will need to install the Cygwin Toolbox. Cygwin is a UNIX-like environment for Windows that includes GCC porting and all the necessary development tools, including the Automake and GNU Debugger (GNU Debugger,gdb). Cygwin is built on the basis of the Cygwin1.dll library. Cygwin's alternative solution is minimalist GNU for Windows (MinGW). The tool is a set of Windows-specific header files and import libraries that are freely available, free to distribute, and are combined with the GNU toolset, which allows you to generate native Windows programs that do not rely on any third-party DLLs. If you want to create a POSIX-compatible Windows application, then MinGW is the best choice. MinGW can even work on Cygwin installations. Solaris and QNX require you to download and install their specific GCC, GNU make binutils, and GDB porting from the Internet.

Assume that you have the appropriate Java Sdk/jre and Eclipse platform SDKs installed, and that they all work correctly. The CDT is available in two "ways": Stable release and trial version (nightly build). Trial run versions are not fully tested, but they provide more functionality and correct current errors. Before installing, check if there is a previous version of the CDT on the disk, and if so, make sure to completely remove it. Because the CDT does not have an uninstall program available, it needs to be removed manually. To check if the previous version exists, go to the directory where the CDT plugin resides: Eclipse/plugins. Next, remove all directories that begin with the ORG.ECLIPSE.CDT name. The last thing to do is to remove the CDT metadata directory or.eclipse.cdt.* from Tadata/.plugins and features.

The next step is to download the CDT binary file. Note: Please download the correct CDT for your operating system. Unfortunately, even though the CDT is written in Java, it is not platform-independent. Next, extract the archive to the temp directory and move all plug-in directory contents from the temp directory to the Eclipse plugins subdirectory. You will also need to move the features directory contents to the Eclipse features subdirectory. Now that the restart Eclipse.eclipse is started again, the update Manager will tell you that it found the changes and asked you to confirm the changes. Now you will be able to see two new items available: C and C + +.

  Create a new project

After installing the CDT in Eclipse, browse to File = + new + project, where you will find three new available project types: C ("Standard C Make Project"), C + + ("Standard + + Ma Ke Project ") and" Convert to C or C + + Projects ". Start with standard make C + + project and create a source code file for your project. Right-click in the C + + Projects view, and select New = simple = file. Name your files and save it. You might use this method to create many header files, as well as C + + implementation code files. Finally, of course, Makefile,gnu make will use it to build the binaries. Use the common GNU make syntax for this Makefile (see Resources). Keep in mind that Makefile requires you to use the Tab character instead of a space to produce indentation.

You will typically import the existing source code into Eclipse (see Figure 2). The CDT provides a convenient way to perform this operation by using the Import Wizard to copy files from the file system directory to the Workbench. Go to the main menu bar and select file = Import = File System. Click Next to open the source directory and select the directory where you want to add the files. Click Select All to select all the resources in the directory, and then check from beginning to end to deselect those resources that you do not intend to add. Specifies the Workbench project or folder that will be the target for the import. You can also import folders and files by dragging folders and files from the file system and placing them in the Navigator view, or by copying and pasting them.

Figure 2. Import the existing source code into the CDT project

  Key CDT IDE Features

The CDT IDE is built on the basis of the universal extensible editor provided by the CDT UI plug-in. However, the module is still in development, so it still lacks some important utilities, such as a class browser or a language document browser. The main features of the CDT IDE are:

Syntax highlighting: The CDT IDE recognizes C + + syntax and provides fully configurable code coloring and code formatting for syntax highlighting:

Figure 3. Incorrect syntax error marking after compilation is unsuccessful

Outline: The Outline window module provides a quick view of the procedures, variables, declarations, and functions that appear in the source code. With outline, you can easily find the appropriate references in your source code, or even search all project source code.

Code-Assist: This code completion function is similar to the functionality found in Borland C + + Builder or MS Visual Studio. It uses code templates and only helps to avoid stupid syntax errors:

  

Figure 4. Code accessibility that helps to use the correct language syntax

Code templates: Code templates that are used by code accessibility are definitions of the standard C + + language syntax structure. You can also define your own code templates to extend your own shortcut keys, such as shortcuts for author or date keywords. You can add a new template and view a complete list of templates in Window = Preferences, c + + = + Code Templates. You can also export and import the template as an XML file.

  

Figure 5. Pre-defined C + + code templates

Code history: You can also track local changes in your project's source code, even if you are not using CVS or other source code version management software. Right-click on the selected file and choose Compare with + = Local History from the context menu ... :

  

Figure 6. Use the Local history feature to check for changes in your source code

  Build and run the project

The CDT provides an easy way to set project build options. The CDT relies on three GNU tools: gcc, GDB, and make. Therefore, the dependency requirements for GDB used for debugging or for the compilation of GCC and make require these applications to be available to the platform that the user wants to use. Most Linux (typically and POSIX) source code packages use the Autoconf script to check the build environment, so you must run the Configure command, which creates "Makefile" before compiling. CDT does not provide a way to edit autoconf scripts, so it is necessary to write them manually; However, you can configure the build option to invoke the Configure command before compiling.

If you build the project by calling the Make command, the default setting is fine, but if you build it using a more complex method, you must enter the appropriate command in the Build Command text box (for example, Make-f make_it_all). Next, in the C + + Projects view, select C + + project, and then right-click and select Rebuild Project. All compiled messages from make, compiler, and linker are redirected to the console window:

  

Figure 7. Console window with compiler output

After the compilation is successful, you may want to run your application. All options for running and debugging are located under the Run menu of the main Eclipse menu. However, the option to run the project must be defined earlier. You can do this by going to the main menu (where there are different profiles for running the application). Option to complete this step; For example, one profile can be used for testing purposes, and another profile is used to run the final version. In addition, you can define the parameters you want to pass to the application, or you can set environment variables. Other options are used to set debugging options, such as which debugger to use (GNU gdb or Cygwin gdb). Figure 8 shows the running profile that is being created for the project (run profiles).

Figure 8. Create a run profile for a project

When you go to the C + + Projects view, select your project, right-click and select Properties on the Build Settings tab, you can use more of the common options for building your project. These options primarily affect what happens when a build is stopped when a compilation error is encountered.

  To debug a C + + project

The CDT expands the standard Eclipse debug view to provide the ability to debug C + + code. The debug view allows you to manage debugging or running programs in the workbench. To start debugging the current project, as soon as you switch to the debug view, you will be able to set (and change) breakpoints/monitoring points and track variables and registers in your code, at any time during execution. The debug view displays the stack frame of the pending thread for each target being debugged. Each line routine in the program appears as a node in the tree, and the Debug view shows the process for each target that is running.

Eclipse supports a debugger that is compatible with machine Interface,mi by using the CDT debug mi (CDT) plug-in (one of its components). But what exactly is the MI debugger? In general, third-party GUI debuggers, such as DDD and Xxgdb, rely on GDB's command-line interface when implementing debugging functions. Unfortunately, this interface has been proven to be very unreliable. GDB/MI provides a new machine-oriented interface that is ideal for programs that want to parse the GDB output directly.

  Conclusion

The C/D + + Development Toolkit (CDT) provides a powerful set of plug-ins that help you develop A/C + + application with Eclipse. Although the CDT is still in the development phase, you can take advantage of many of its existing features.

Using the Eclipse Platform for C/D + + development

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.