Introducing CDT

Pawel Leszek

Getting started with CDT -- a C/C++ IDE built with Eclipse technology.

From "C/C++ Development with the Eclipse Platform," first published by IBM developerWorks at http://www.ibm.com/developerWorks. Reprinted with permission.

Figure 1: A C/C++ project in Eclipse

CDT is an open source project (licensed under the Common Public License) that is working towards a fully functional C/C++ Integrated Development Environment (IDE) for the Eclipse Platform. CDT is implemented purely in Java as a set of plug-ins for the Eclipse SDK Platform. Although the project focus is on Linux, CDT works in all environments where GNU developer tools are available, including Win32 (Win 95/98/Me/NT/2000/XP), QNX Neutrino, and Solaris.

Before you download and install the CDT, you first need to ensure that you have the GNU C compiler (GCC) and all the accompanying tools (make, binutils, GDB). If you're running Linux, simply install the development packages using the package manager appropriate for your distribution. On the Windows platform, you'll need to install the Cygwin toolkit (<http://www.redhat.com/software/cygwin/>). Cygwin is a UNIX-like environment for Windows that includes a GCC port along with all necessary development tools, including automake and the GNU Debugger (GDB). The alternate solution for Cygwin is Minimalist GNU for Windows (MinGW) (<http://www.mingw.org/>). MinGW is a better choice if you want to create Windows applications that are POSIX compatible.

To install CDT, you must have the appropriate Java SDK/JRE and Eclipse Platform SDK. CDT is available as either stable releases or nightly builds. Nightly builds have not been fully tested, but they offer more features and correct current bugs. Before installation, check if the previous version of the CDT exists on your disk and, if so, make sure to completely remove it. Because there are no uninstallers available for the CDT, you will need to do this manually. To check to see if a previous version exists, go to the directory where the CDT plug-ins reside: eclipse/plugins. Next, remove all directories starting with the org.eclipse.cdt name. The last thing you will need to do is remove the CDT metadata directories or.eclipse.cdt.* from workspace/.metadata/.plugins and features. The next step is to download the CDT binaries (see the official CDT website: <www.eclipse.org/cdt>). Take care to download the correct CDT for your operating system. Next, uncompress the archives into a temporary directory and move all plug-in directory content from there to the Eclipse plugins subdirectory. You will 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 has found changes and will ask you to confirm them. You'll now be able to see that two new projects are available: C and C++.

Creating new projects

After installing CDT in Eclipse, navigate to File => New => Project, where you will find three new types of projects available: 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 source code files for your project. In the C/C++ Projects view, right-click and select New => Simple => File. Name your file and save it. You'll probably create many files for header and C/C++ implementation code files in this way. The last one is, of course, makefile, which will be used by GNU Make for building binaries. Use the usual GNU make syntax for this makefile. Remember that makefile,s require you to make indented lines using the Tab character and not spaces.

CDT offers an easy way to import existing source code. Go to the main menu bar and select File => Import => File System. Click Next and open the source directory and select the directories from which you would like to add files. Click Select All to select all resources in the directory, and then go through and deselect the ones that you do not want to add. Specify the Workbench project or folder that will be the import destination. You can also import folders and files by copying and pasting them, or by dragging them from the file system and dropping them in the Navigator view.

Key CDT IDE features

The CDT IDE is built around a universal, extensible editor provided by the CDT UI plug-in. The main features of the CDT IDE are:

CDT also extends the standard Eclipse Debug View with functions for debugging C/C++ code. The Debug View allows you to manage the debugging or running of a program in the Workbench. To start debugging the current project, simply switch to the Debug View and you will be able to set (and change at anytime during execution) breakpoints/watchpoints in the code, trace variables, and registers.

About the Author

Pawel Leszek is an independent software consultant and an author specializing in Linux/Win/Mac OS system architecture and administration. Pawel is the author of a series of articles for LinuxWorld and is a Linux columnist for the Polish edition of PC World. He lives in Warsaw.