If you are using Eclipse package other than Eclipse IDE for C/C ++ Developers, you need to add add an extension plugin to the current Eclipse to program with.
Importing your C/C source files into Eclipse Using the CVS Repository Exploring perspective, you can check out modules or directories into existing projects, or create new projects. A common scenario that you may encounter when starting to use the CDT, is determining how to bring existing C/C source files into Eclipse. There are a number of ways to do this. The scenarios described below are recommended approaches. Creating a project from source files in CVS If your existing source tree is managed in CVS, you can use the CVS Repository perspective to 'Checkout As.' Any folder in the repository. The first time you 'Checkout As.'
, the New Project wizard launches and you need to create a C or C project for the folder. For more information, see,. After you perform a checkout operation, a CVS checkout of the project occurs into the project's location.
It is recommended that you eventually add and commit the CDT project files back into CVS. These files include.project,.cdtproject, and.cdtbuild (for Managed Build projects) and are located at the root folder of each CDT project. Bringing code into the IDE from CVS differs slightly, depending on what you're importing:. an existing C/C project. existing C/C code that isn't part of a project.
existing C/C code that needs to be added to an existing project Importing a C/C project from CVS To check out an existing C/C project from the CVS repository into your workspace, right-click the project in the CVS Repositories view, and select Check Out from the menu. A project with the same name as the CVS module is checked out in to your workspace. Importing C/C code from CVS To check out existing C/C code that is not part of a project:. Right-click the module or directory in the CVS Repositories view and choose Check Out As. From the menu.
The Check Out As wizard displays. Choose how to check out this project:. as a project configured using the New Project wizard or:. as a new project in the workspace or:.
as a Standard Make C/C Project - if you need to create your own Makefile to integrate with an existing build process Choose the workspace location for this project, then the CVS tag to check out. Click Finish to exit the Check Out As dialog. Click Next to continue. Importing C/C code into an existing project To import a directory full of C/C code into an existing project:.
Right-click the module or directory in the CVS Repositories view and choose Check Out As from the menu. The IDE displays the Check Out As dialog. Choose Check out into an existing project, and then click Next. The IDE displays the Check Out Into dialog:. Select an existing project from the list, and then click Finish to add the code from CVS to the selected project.
Creating new projects from existing source roots If your resource code is not managed in CVS but is available from the file system, then you need to perform two steps:. Identify a 'root folder' of your source code tree. Create a new C/C project using the New Project Wizard, and specify the 'root folder' as a non-default location of the new project.
Typically, existing projects will have their own makefiles, so you should create a new Make C/C project. For more information see. To help you to identify a root folder for your project, consider the following guidelines:. all source code for the project is available on or beneath the root folder.
the build results are also produced in or beneath the root folder. there is often a makefile in the root folder. In complex projects, the makefile in the root folder calls other makefiles in other directories to produce the build results. external header files and library files do not need to be in or beneath the root folder. The resources for the project are maintained in the remote location specified, not in the workspace folder for Eclipse. However, your existing folder structure is displayed in the C/C Projects view. Meta data for the project, such as the index for the project and the link to the existing source, is stored in the metadata directory in the workspace folder.
For more information on the workspace folder, see Workbench User Guide Tasks Upgrading Eclipse. After you create a CDT project, you cannot easily move it or redefine its root folders. If you need to, you can delete the CDT project (without deleting its contents) and then recreate it specifying a different non-default location. Import your C/C source file system Another approach would be to create a C/C Project and then import your existing file system.
For more information about importing, see Workbench User Guide Tasks Importing Importing resources from the file system. This approach copies the files from your file system to an Eclipse Workbench project or folder.
Your original source files remain unchanged and it is the copies of the files that will be edited, built and debugged using the CDT. When you have successfully imported your existing file system, the folder structure is displayed in the C/C Projects view. Again, you should identify an appropriate 'root folder' to import from.
Tip:. Importing your existing file system can consume significant disk space depending on the size of your files. Your files may become detached from an existing source control system that previously referenced the original file location such as a ClearCase view.
This article, which is a follow-up to ',' is intended for C developers who want to learn C development using the Eclipse CDT. A simple C application is developed in the article. The application makes use of the C STL. Readers should be familiar with the STL, as well as with basic object-oriented programming principles such as inheritance and polymorphism. A familiarity with Eclipse will be helpful, but is not required. Before we start You need to install the following:.
We're using the CDT, which is a plug-in to Eclipse, so of course you need Eclipse. The article uses Eclipse V3.2. Java Runtime Environment We're building a C application, but we're using Eclipse. Eclipse is a Java application itself, so it needs a Java Runtime Environment (JRE). The article uses Eclipse V3.2, which requires a JRE of V1.4 or higher. If you want to also use Eclipse for Java development, you'll need a Java Development Kit (JDK). This article is about the CDT, so you'll need it, of course.
For instructions on installing the CDT on early versions of Eclipse, read a ' (developerWorks 2003). If you're using Microsoft Windows®, you will find Cygwin — which provides a Linux®-like environment on Windows — helpful.
GNU C/C Development Tools The CDT uses the standard GNU C/C tools for compiling your code, building your project, and debugging the applications. These tools are GNU Compiler Collection (GCC) for C (g), make, and the GNU Project Debugger (GDB).
If you're a programmer using Linux or Mac OS X, there's a pretty good chance these tools are installed on your machine. The article contains instructions for setting up these tools for Windows. The Eclipse CDT The Eclipse CDT is an Eclipse plug-in that transforms Eclipse into a powerful C/C IDE. It was designed to bring many of the great features Eclipse enjoyed by Java developers to C/C developers, such as project management, integrated debugging, class wizards, automated builds, syntax coloring, and code completion. When Eclipse is used as a Java IDE, it leverages and integrates with the JDK.
Similarly, the CDT leverages and integrates with standard C/C tools, such as g, make, and GDB. This has lead to it becoming very popular on Linux, where those tools are readily available and used for most C development. The CDT can be set up on Windows to use the same tools. There is also an ongoing effort to get the CDT to work with Microsoft's C tools to make it even more attractive to Windows C developers. Installing the CDT We start by assuming you installed Eclipse and can run it.
If not, consult Eclipse's Web site for getting up and running. Let's install the CDT. The CDT is an Eclipse plug-in, so it uses Eclipse's Software Updates feature. Select Help Software Updates Find and Install. Eclipse Software Updates. After you finish installing CDT, you'll be asked to restart Eclipse.
Go ahead and do that. Once Eclipse restarts, the CDT will be ready to go. Windows configuration If you're running Eclipse on Linux or Mac OS X, you're ready to start using the CDT to develop a C application. If you're on Windows, there might be a few more steps. As mentioned, CDT relies on the standard GNU C development tools: g, make, and GDB. These are usually included on Linux or Mac OS X.
They're usually not included with Windows. But don't worry. These tools can be easily installed on Windows. Perhaps the easiest way is to install Cygwin. Cygwin provides Linux-like environment on Windows (see ).
When installing Cygwin, you'll be asked to pick the packages you want to install. Make sure to go into the development section and select gcc: g, make, and GDB. This will cause their prerequisites to be installed, too.
Once you're done installing Cygwin, you'll need to add g, make, and GDB to your path. The easiest way to do this is to add Cygwin's bin directory to your path, since that's where g, make, and GDB can be found. Once that's done, restart Eclipse.
Playing the lottery At this point, we should be ready to start developing our application with CDT. Let's pause to figure out what we want to develop. The sample application is a simple command-line program for generating lottery numbers. Many states have lotteries, and the rules vary quite a bit.
We'll allow the user to pick which state lottery he wants to generate numbers for. This will provide us a good way to use C's support for polymorphic behavior. Creating the project Eclipse uses the concepts of perspectives to allow for various plug-ins to customize their commands and views. Eclipse starts off by default in the Java perspective. CDT includes its own perspective, so we'll want to switch to that. To do that, select Window Open Perspective Other. You should see a list of perspectives available to you.
Select the C/C perspective and click OK. Select C/C perspective. Related topics. (Alex Ruiz, developerWorks): Learn how to execute C/C code analysis tools with Codan in Eclipse. Get an overview of the CDT in '.'
. Dig deep into the CDT's architecture in the five-part series titled '.' . As someone interested in C/C development, you might want to check out a trial of IBM's. Windows developers can learn about migrating to the CDT in '.'
. Windows developers can also check out the, a project for incorporating Microsoft's compiler and debugger with CDT.
Learn about, the GNU C/C tools for Windows included with Cygwin. Download a Linux-like environment for Windows. It consists of two parts: A DLL that acts as a Linux API emulation layer providing substantial Linux API functionality and a collection of tools that provide a Linux look and feel.
The download information contains the latest information about the available versions of CDT. Check out the '.' .
For an introduction to the Eclipse platform, see '.'