"Go" with the CDT control of the Eclipse platform for C + + development

Source: Internet
Author: User
Tags db2 posix

Original address: http://www.ibm.com/developerworks/cn/linux/opensource/os-ecc/

Pawel Leszek is developed with the Eclipse platformStudio BA writer who is an independent software consultant and writer specializing in the architecture and management of Linux/win/mac OS systems. He has experience in many operating systems, programming languages, and network protocols, especially Lotus Domino and DB2. Pawel is still LinuxWorldThe author of a series of articles, and PC WorldThe Polish version of the Linux columnist. Pawel lives in Warsaw with his wife and his lovely little daughter. You are welcome to ask questions and make comments; you can email the author directly ([email protected])。

Summary: 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.

tags for this article: c, Eclipse, Linux

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 (see the Resources section later in this article for links) is dedicated to providing a full-featured, 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 (see Resources for links). 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 cygwin1.dll base of the library. Cygwin's alternative solution is minimalist GNU for Windows (MinGW) (see Resources for links). 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 (see Resources for links).

The

assumes 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 plug-in resides: eclipse/plugins . Next, all directories that start with the org.eclipse.cdt name are removed. The last thing to do is from workspace/.metadata/.plugins and features To remove the CDT metadata directory or.eclipse.cdt.* .

The next step is to download the CDT binary file. Note: Please download the correct CDT for your operating system. Unfortunately, even if the CDT is written in Java, it is not platform-independent. Next, extract the archive files 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 features move the directory contents to the Eclipse features subdirectory. Now, restart Eclipse. After Eclipse starts again, update Manager tells you that it found the changes and asks if you want to confirm them. 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 and project, where you will find three new types of available projects: C ("Standard C Make Project"), C + + ("Standa Rd C + + make 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 file 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 Nextto open the source directory and select the directory where you want to add the file. 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 author shortcuts for 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 dependencies on GDB used for debugging or GCC and make for compilation are required for 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 commands before compiling configure .

If you build the project by invoking make a 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 run ... option in the main menu (where there are different profiles for running the application); For example, you can use one profile for testing purposes and another profile for running 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 (see Resources for links), rely on GDB's command-line interface when implementing debugging functionality. 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.

Concluding remarks

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.


Resources

  • You can refer to the original English text on the DeveloperWorks global site in this article.
  • Please join the Eclipse platform community and download the platform from eclipse.org . The Eclipse platform source code is licensed under Common public License. On eclipse.org, you'll also find terminology glossaries and descriptions for the Eclipse project, as well as technical articles and newsgroups. The Eclipse Platform white Paper details the main components and features of Eclipse.
  • Download the components of the CDT project from eclipse.org.
  • Please visit the newsgroups on eclipse.org for technical discussions and issues related to C + + plugins.
  • Developers can participate in discussions with the C + + IDE implementation by creating a Developer mailing list (developer mailing lists) for each component in the project.
  • The CDT project uses Bugzilla as its error and function tracking system. Entering an error/feature report on the Eclipse bugzilla page is as simple as filling out a Web form.
  • For an introductory article on the Eclipse platform and how it works, see the developerWorks article "Working the Eclipse platform c6> ".
  • To start developing applications using the Eclipse platform, see the developerWorks article written by David Gallardo, " Getting started with the Eclipse platform ".
  • If you are interested in creating your own Eclipse plug-in, see the developerWorks article " Developing Eclipse plug-ins " written by David Gallardo.
  • Download the Cygwin Toolbox from Red Hat.
  • Download the MinGW Toolbox from mingw.org.
  • Learn more about the GNU make syntax on gnu.org.
  • Download the dddGUI debugger from gnu.org.
  • Download the xxgdbGUI Debugger.
  • Visit WebSphere Studio plug-incentral to get the directory of plugins that have been validated as "ready for WebSphere Studio software".
  • Learn an extension of IBM WebSphere Studio Tools, which provides information and tools to help you use these tools. Since all WebSphere Studio tools are based on the WebSphere Studio Workbench (WebSphere Studio Workbench), and the Workbench is based on the Eclipse framework, it is easy to extend the functionality by using Eclipse Help extensions Product documentation. See the article " Adding Self-Help support for WebSphere Studio Tools by extending their Eclipse help Systems."
  • Please find more Eclipse user references on developerWorks .

About the author

Pawel Leszek is a writer at Studio B , an independent software consultant and writer specialising in Linux/win/mac OS system architecture and management. He has experience in many operating systems, programming languages, and network protocols, especially Lotus Domino and DB2. Pawel is also the author of a series of articles on LinuxWorld , as well as the PC World Polish version of Linux columnist. Pawel lives in Warsaw with his wife and his lovely little daughter. You are welcome to ask questions and make comments, and you can email the author directly (email protected).

"Go" with the CDT control of the Eclipse platform for C + + 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.