CC ++ development with Eclipse platform

xiaoxiao2021-03-06  106

Author: Pawel Leszek dispatch time: 2004.05.13

We will outline how to use the Eclipse platform in the C / C development project. Although Eclipse is mainly a Java development environment, its architecture ensures support for other programming languages. In this article, you will learn how to use C / C development toolbox (C / C Development Toolkit, CDT), which is the best C / C toolbox available for Eclipse. C and C languages ​​are the most popular and most popular programming languages ​​in the world, so the Eclipse Platform provides no support for C / C development. Because the Eclipse platform is just a framework for the developer tool, it does not directly support C / C ; it uses external plug-in to support. This article will show you how to use CDT - a set of plugins for C / C development. The CDT project is committed to providing a full C / C integrated development environment (Ide) for the Eclipse platform. Although the project's focus is Linux, it works in all environments that can use the GNU developer tool (including Win32 (Win 95/98 / ME / NT / 2000 / XP), QNX Neutrino and Solaris platforms. CDT is an open source item (according to CommON Public License), which is fully implemented using Java, which is a set of plugins of the Eclipse SDK platform. These plugins add C / C perspective to the Eclipse Workbench (Workbench), which can now use many views and wizards and advanced editing and debugging support to support C / C development. Due to its complexity, CDT is divided into several components, which are in the form of a separate plug-in. Each component operates as an independent project, with its own set of submitters, error categories, and mailing lists. However, all plugins are required for CDT normally. Below is a complete list of CDT plug-in / components: the primary CDT plug-in is a "frame" CDT plugin. The CDT function Eclipse (CDT Feature Eclipse) is a CDT function component (Feature Component). CDT core (CDT Core) provides a core model, CDOM, and core components (Core Component). The CDT UI is the core UI, view, editor, and wizard. CDT launch (CDT Launch) provides a startup mechanism for external tools such as compilers and debuggers. CDT debug core provides debugging. The CDT debug UI (CDT Debug UI) provides a user interface for the CDT debug editor, view, and wizard. CDT debug MI (CDT Debug MI) is an application connector for debuggers compatible with the MI. Now let's study how to use these components in practical applications. Figure 1 shows the C / C items in Eclipse:

Figure 1. Editing C / C projects in Eclipse with CDT plug-in

Installing and running CDT Before downloading and installing CDT, you must first ensure that GNU C Compiler, GCCs, and all included tools (Make, Binutil and GDB) are available. If you are running Linux, you will install the development package by using the package manager that applies to your distribution. On the Windows platform, you will need to install the CYGWIN toolbox. Cygwin is a class UNIX environment for Windows, which includes GCC transplants and all necessary development tools, including Automake and GNU debuggers (GNU Debugger, GDB). Cygwin is built on the basis of the Cygwin1.dll library. Cygwin's alternate solution is Minimalist GNU for Windows (Mingw). This tool is a set of free-to-use Windows header files and import libraries that are freely distributed, these header files and import libraries and GNU tools (they allow you to generate local Windows programs that do not depend on any third-party DLL) integrate. If you want to create a Posix's compatible Windows application, then MingW is the best choice. MINGW can even work on Cygwin installation. Solaris and QNX require you to download and install your specific GCC, GNU make binutils and GDB transplant from the Internet. Suppose you have the appropriate Java SDK / JRE and Eclipse platform SDK, and they are running normally. CDT is available in two "ways": stable distribution and trial run (Nightly Build). The trial running version has not been fully tested, but they provide more features and correct current errors. Before installing, check if there is a previous version of the CDT on the disk, if there is, make sure it is completely removed. Because the CDT is not available unloading, it needs to be manually removed. In order to check if the previous version is existing, go to the directory where the CDT plugin is resident: Eclipse / Plugins. Next, remove all directories that start with the org.eclipse.cdt name. The last thing you need to do is to remove the CDT metadata directory or.eclipse.cdt. *. /. The next step is to download the CDT binarily. Note: Please download the correct CDT suitable for your operating system. Unfortunately, even if the CDT is written in Java, it is not unrelated to the platform. Next, unfolding the archive file into the temporary directory, from the temporary directory to move all plug-in directory content to the Eclipse Plugins subdirectory. You also need to move the Features directory content to the Eclipse Features subdirectory. Now restart Eclipse. After Eclipse starts again, the Update Manager will tell you that it discovers changes and asks if you confirm these changes. Now you will be able to see two available new projects: C and C . Creating a new project After installing CDT in Eclipse, browse to file => new => Project, where you will find three new available item types: C ("Standard C make Project"), C ("STANDARD C Make Project ") and" Convert to C OR C Projects ".

Start with "Standard Make C Project" to create a source code file for your project. In the C / C Projects view, click the right mouse button and select New => Simple => file. Name your files and save it. You may use this method to create a number of header files and C / C implementation code files. Finally, it is Makefile, and GNU Make will use it to build binaries. Use the common GNU Make syntax for this makefile (see Resources). Keep in mind: makefile requires you to use Tab characters instead of spaces. You usually import existing source code into Eclipse (see Figure 2). CDT provides a convenient way to perform this: ie the import wizard, copy the file from the file system directory to the workbench. Go to the main menu bar, select File => Import => File System. Click Next, open the source directory, select the directory you want to add the file. Click Select All to select all resources in the directory, then check from head to tail, deselect those resources you don't plan to add. Specifies a workbench project or folder that will be imported. You can also import folders and files by dragging folders and files from the file system and put them in the Navigator view, or by copying and paste. Figure 2. Import existing source code into the CDT project

The key CDT IDE function CDT IDE is built on the general-purpose scalable editor provided by the CDT UI plugin. However, this module is still in the development phase, so it still lacks some important utilities, such as a class browser or a language document browser. The main function of the CDT IDE is: syntax highlights: CDT IDE identifies C / C syntax, and highlights the syntax to provide full configurable code coloring and code formatting function:

Figure 3. Syntax error tag that highlighted after unsuccessful compilation

Outline: The OUTLINE window module provides a quick view of the process, variables, declarations, and functions that appear in the source code. With OUTLINE, you can easily find the appropriate references in the source code, or even search all item source code. Code Auxiliary: This code completion function is similar to the feature that can be 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 use the correct language syntax

Code Template: The code template used by the code assist feature is the definition of the standard C / C language syntax structure. You can also define your own code template to extend your own shortcuts, such as shortcuts for Author or Date keywords. In Window => Preferences => C / C => Code Templates, you can add a new template and view the full template list. You can also export and import the template as an XML file.

Figure 5. Predefined C / C Code Template

Code History: Even if you don't use CVS or other source code management software, you can track local changes in the project source code. Right click on the selected file, select Compare with => local history ...: from the context menu.

Figure 6. Check the changes in the source code with the local history function

Build and run the project CDT provides a simple way to set up item build options. CDT depends on three GNU tools: GCC, GDB and Make. Therefore, these applications can be used for the platform you want to use for the GDB or the dependence of the GCC and MAKE for compilation. Most Linux (usually and class POSIX) source code packages use the AutoConf script to check the build environment, so you must run the configure command, which is created "makefile" before compiling. CDT does not provide a method of editing an AutoConf script, so you must write them manually; however, you can configure the build option to call the configure command before compiling. If you build a project by calling the Make command, the default setting is no problem, however, if a more complex method is used, you must enter the appropriate command (for example, make -f make_it_all) in the Build Command text box. Next, in the C / C Projects view, select C / C Project, then right-click and select Rebuild Project. All compile messages from the make, compiler, and linkers are redirected to the console window: Figure 7. Console window with compiler output

After successful compilation, you may want to run your app. All options for running and debugging are located under the RUN menu of the primary Eclipse menu. However, you must define an option for running a project earlier. This step can be done by turning to the main menu (where there is a Run ... option in different profiles for running applications); for example, a profile can be used for testing purposes, and another profile can be Used to run the final version. In addition, you can define the parameters you want to pass to the application, or you can set the environment variable. Other options are used to set the debug option, such as which debugger (GNU GDB or Cygwin GDB) is used. Figure 8 shows that the run profile (Run Profile) is being created for the project.

Figure 8. Creating a profile for the project

转载请注明原文地址:https://www.9cbs.com/read-126751.html

New Post(0)