Use the eclipse platform for C/C ++ Development

Source: Internet
Author: User
Tags pc world

How to Use the C/C ++ development toolbox (CDT)

Level: Intermediate

Pawel Leszek (pawel.leszek@ipgate.pl)
Independent software consultant
July 2003

We will outline how to use the eclipse platform in C/C ++ development projects. Although eclipse is mainly a Java development environment, its architecture ensuresProgramming Language. In this article, you will learn how to use the C/C ++ Development Toolkit (C/C ++ development toolkit, CDT ), it is the best C/C ++ toolkit for eclipse.

C and C ++ are the most popular and commonly used programming languages in the world. Therefore, it is not surprising that the eclipse platform provides support for C/C ++ development. Because the eclipse platform is only a framework used for developer tools, it does not directly support C/C ++; it uses external plug-ins to provide support. This article will show you how to use CDT-a set of plug-ins for C/C ++ development. CDT project (for links, refer to the references section later in this article) is committed to providing fully functional C/C ++ integrated development environment (integrated development environment, IDE ). Although this project focuses on Linux, it is available in all environments where GNU developer tools are available (including Win32 (WIN 95/98/ME/NT/2000/XP) QNX neutrino and Solaris platforms.

CDT is an open-source project fully implemented in Java (licensed according to the common public license) and serves as a set of plug-ins for the eclipse SDK platform. These plug-ins Add the C/C ++ perspective to the eclipse workbench, now, the latter can support C/C ++ development with many views and Wizard and advanced editing and debugging support.

Due to its complexity, CDT is divided into several components, all of which adopt the form of independent plug-ins. Each component operates as an independent project with its own set of submitter, error category, and email list. However, all plug-ins are necessary for the normal operation of CDT. The following is a complete list of CDT plug-ins/components:

    • Master CDT plug-in (primary CDT plug-in)Is the "Framework" CDT plug-in.
    • CDT function eclipse (CDT feature eclipse)Is the CDT function component (feature component ).
    • CDT Core)Provides core models, cdom, and core component ).
    • CDT UIIs the core UI, view, editor and wizard.
    • CDT launch)Provides a startup mechanism for external tools such as compilers and debuggers.
    • CDT debugging Core)Provides debugging functions.
    • CDT debug UI)Provides a user interface for the CDT debugging Editor, view, and wizard.
    • CDT debug Mi)Is an application for the mi-compatible debugger.ProgramConnector.

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

Figure 1. Edit the C/C ++ project in eclipse with the CDT plug-in

install and run CDT
before downloading and installing CDT, make sure that the gnu c compiler (gnu c compiler, GCC) and all accompanying tools (make, binutil, and GDB) are available. If you are running Linux , you only need to install the development package by using the Package Manager for your distribution. On the Windows platform, you will need to install the cygwin Toolkit (see references for links ). Cygwin is a UNIX-like environment for windows. It includes GCC porting and all necessary development tools, including automake and GNU Debugger (GNU Debugger, GDB ). Cygwin is built on the cygwin1.dll library. The alternative solution for cygwin is minimalist GNU for Windows (mingw) (see references for links ). This tool is a set of Windows-specific header files and imported/imported files that can be freely obtained and distributed for free, these header files and imported libraries are combined with the GNU tool set (which allows you to generate local Windows programs that do not depend on any third-party DLL. If you want to create a POSIX-compatible windows application, mingw is the best choice. Mingw can even work on cygwin installation. Solaris and QNX require you to download and install their specific GCC, GNU make binutils, and GDB ports from the Internet (see references) to obtain the link ).

Assume that you have installed the appropriate Java SDK/JRE and eclipse Platform SDK, and they all run properly. CDT can be used in either of the following ways: stable release and test run (nightly build ). The trial version has not been fully tested, but they provide more features and correct the current error. Before installation, check whether the previous version of CDT exists on the disk. If so, ensure that it is completely removed. Because CDT does not have an available uninstall program, you need to manually remove it. To check whether the previous version exists, go to the directory where the CDT plug-in resides:Eclipse/plugins. Then, remove allOrg. Eclipse. CDTThe directory starting with the name. The last thing to do isWorkspace/. Metadata/. pluginsAndFeaturesRemove the CDT metadata directoryOr. Eclipse. CDT .*.

The next step is to download the CDT binary file. Note: Download the correct CDT suitable for your operating system. Unfortunately, even if the CDT is written in Java, It is not platform-independent. Next, decompress the archive file to the temporary directory, and move all the plug-in contents from the temporary directory to the eclipsePluginsSubdirectory. You also needFeaturesMove the directory content to eclipseFeaturesSubdirectory. Now, restart eclipse. After eclipse is started again, the update manager will tell you that it has detected changes and ask if you are sure of these changes. Now you can see two available new projects: C and C ++.

Create a new project
After installing CDT in eclipse, browseFile => New => Project, Where you will find three new available project types: C ("Standard C make project"), c ++ ("Standard C ++ make project ") and "convert to C or C ++ projects ". Create a project for your project from "standard make C ++ Project"Source codeFile. In the C/C ++ projects view, right-click and selectNew => simple => File. Name your file and save it. You may use this method to create many header files and C/C ++ implementations.CodeFile. The last step is makefile. GNU make will use it to build binary files. Use the common GNU make syntax for this makefile (see references ). Remember: makefile requires that you use TAB characters instead of spaces to produce reduction.

You usually import the existing source code to eclipse (see figure 2 ). CDT provides a convenient way to perform this operation: Use the import Wizard to copy files from the file system directory to the workbench. Go to the main menu bar and selectFile => Import => File System. ClickNextOpen the source directory and select the directory of the file you want to add. ClickSelect AllTo select all resources in the directory, and then check from start to end. deselect the resources you do not want to add. Specifies the workbench project or folder to be imported as the target. You can also drag folders and files from the file system and put them into the navigator view, or import folders and files by copying and pasting them.

Figure 2. Import existing source code to the CDT Project

Key CDT ide Functions
Cdt ide is built on the general extensible editor provided by the cdt ui plug-in. However, this module is still in the development stage, so it still lacks some important utilities, such as class browsers or language document browsers. The main functions of cdt ide are:

    • Syntax highlighted: CDT ide recognizes C/C ++ syntax and provides fully configurable code coloring and code formatting for syntax highlighting:

Figure 3. syntax error mark highlighted after unsuccessful Compilation

    • Outline: The outline window module provides a quick view of the processes, variables, declarations, and functions that appear in the source code. With outline, you can easily find the appropriate reference in the source code, or even search for the source code of all projects.
    • Code assistance: This Code Completion function is similar to a feature that can be found in Borland C ++ builder or MS Visual Studio. It usesCode TemplateAnd only helps avoid stupid syntax errors:

Figure 4. Code assistance that helps you use the correct language syntax

    • Code Template: The Code Template used by the Code auxiliary function is the definition of the standard C/C ++ syntax structure. You can also define your own code template to expand your own shortcut keys, suchAuthorOrDateKeyword shortcut. InWindow => preferences => C/C ++ => code templatesYou can add a new template and view the complete template list. You can also export and import templates as XML files.

Figure 5. pre-defined C/C ++ Code Template

    • Code history: You can track local changes in the project Source Code even if you do not use CVs or other source code version management software. Right-click the selected file and chooseCompare with => local history...:

Figure 6. Use the local history function to check changes in the source code

Build and run the project
CDT provides an easy way to set project building options. CDT depends on three GNU tools: GCC, GDB, and make. Therefore, the dependencies between GDB for debugging or GCC and make for compilation require that these applications can be used on platforms that users want to use. Most Linux (usually and POSIX-like) source code packages use Autoconf scripts to check the Build Environment, so you must runConfigureCommand to create a "makefile" before compilation ". CDT does not provide methods to edit Autoconf scripts, so you must write them manually. However, you can configure build options to call them before compilation.ConfigureCommand.

If you callMakeIf you use a more complex method to build a project, you must enter an appropriate command in the build command text box (for example,Make-F make_it_all). Next, in the C/C ++ projects view, selectC/C ++ Project, Right-click and selectRebuild project. All compilation messages from make, compiler, and linked programs are redirected to the console window:

Figure 7. Console window with compiler output

After compilation, you may want to run your application. All the options for running and debugging are located under the run menu of the main eclipse menu. However, the options used to run the project must be defined earlier. You can go to the main menu (where there are different profiles used to run the Application)Run...Option to complete this step; for example, you can use a profile for testing purposes, and use 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 (gnu gdb or cygwin GDB) is used ). Figure 8 shows the running profile being created for the project ).

Figure 8. Create a running summary file for the project

In the C/C ++ projects view, right-click your project and selectPropertiesThen, you can use more common options for building projects. These options mainly affect the occurrence of build stops due to a compilation error.

Debug C/C ++ Projects
CDT extends the standard Eclipse debug view to enable debugging of C/C ++ code. The debug view allows you to manage program debugging or running in the workbench. To start debugging the current project, as long as you switch to the debug view, you will be able to set (and change at any time during execution) Breakpoints/monitoring points in the Code and track variables and registers. The debug view displays the stack framework of the suspended threads for each target being debugged. Each thread in the program appears as a node in the tree, and the debug view displays the processes of each target running.

Eclipse uses the CDT debugging mi (CDT debug mi) Plug-in (one of its components) to support a debugger compatible with machine interfaces (MI. But what is the MI debugger? Generally, third-party GUI debuggers such as DDD and xxgdb (see references for links) depend on GDB's command line interface, CLI ). Unfortunately, it is proved that this interface is very unreliable. GDB/MI provides a new machine-oriented interface, which is very suitable for programs that want to directly parse GDB output.

Conclusion
The C/C ++ Development Toolkit (CDT) provides a set of powerful plug-ins that help you develop C/C ++ applications using eclipse. Although CDT is still in the development stage, you can use its existing functions.

References

  • Please join the eclipse PlatformCommunityAnd download the platform from eclipse.org. The source code of the eclipse platform is licensed according to the common public license. At eclipse.org, you will also find the glossary and descriptions about eclipse projects, as well as the technologyArticleAnd newsgroups. The eclipse platform white paper describes in detail the main components and functions of Eclipse.

  • Download the components of the CDT project from eclipse.org.
  • Visit the newsgroup on eclipse.org to obtain technical discussions and problems related to the C/C ++ plug-in.
  • Developers can participate in implementation discussions with C/C ++ ide by creating a developer mailing lists for each component in the project.
  • The CDT project uses Bugzilla as its error and function tracking system. Entering an error/function report on the eclipse Bugzilla page is as easy as entering a web form.
  • For more information about the eclipse platform and how it works, seeDeveloperworksArticle "working the eclipse platform ".
  • To start using the eclipse platform to develop applications, seeDeveloperworksArticle "getting started with the eclipse platform ".
  • If you are interested in creating your own Eclipse plug-in, refer toDeveloperworksThe article "Developing Eclipse plug-ins ".
  • Download the cygwin toolkit from red hat.
  • Download the mingw toolbox from mingw.org.
  • Learn more about the GNU make syntax at gnu.org.
  • Download the ddd gui debugger from gnu.org.
  • Download the xxgdb GUI debugger.
  • Visit WebSphere Studio plug-in central to obtain the directory of the plug-in that has been verified as "ready for WebSphere Studio software.
  • Learn an extension of IBM WebSphere Studio Tools that provides information and tools that help you use these tools. Because all WebSphere Studio Tools are based on the WebSphere Studio workbench and the workbench is based on the eclipse framework, it is easy to use the eclipse help extension function to expand the product documentation. See the article "adding self-help support to WebSphere Studio Tools by extending their eclipse help systems ".
  • Please goDeveloperworksFor more eclipse user references.
About the author
Pawel Leszek is a writer of Studio B. He is an independent software consultant and writer specializing in Linux/win/Mac OS system architecture and management. He has many experience in operating systems, programming languages and network protocols, especially Lotus Domino and DB2. Pawel orLinuxWorldThe author of the previous series of articles andPC WorldLinux columnist for the Polish version. Pawel lives in Warsaw with his wife and lovely little daughter. You can send an email (pawel.leszek@ipgate.pl) directly to the author ).

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.