Motivation

Eclipse is a powerful development environment. Unfortunately, setting up Eclipse as an environment to develop gcc is non-trivial. This page details the steps I have used to get gcc running in my own workspace. Note that you need a machine with more than 2GBs of RAM for the initial project creation to work.

Installing Eclipse

First download and install Eclipse. You’ll need version 3.3 or newer. You can download a version of eclipse 3.3 that comes with the newest CDT pre-installed. Get the necessary plug-ins You will require two plug-ins to work on gcc: a subversion plug-in so you can check the code out of the gcc repository, and the EclipseCDT (C Development Tool) which provides support for C development in Eclipse. One possible SVN plug-in is available at the update site:

If you didn't get a version of eclipse that comes with the CDT pre-installed, look here for how to install CDT. If you already know how to install new eclipse plug-ins the CDT update site is:

If you have never installed an Eclipse plug-in take a look at: http://wiki.eclipse.org/CDT/User/FAQ#Download_and_Installation

Setup new workspace and SVN repository

Setup a Workspace

The first step in getting gcc up for development is setting up a workspace, and then adding a subversion repository to it. Eclipse will have a suggestion for the workspace (it is just a directory) when it starts initially, you can use this workspace. If you do other development in Eclipse you might want to make a separate workspace for gcc development. To switch to a new workspace, in eclipse go to File>Switch Workspace>Other and pick a new empty folder. Setup a repository and new project Once you have a workspace selected, you can add a SVN repository to that workspace and create a new project with the gcc source in it.

  1. To start things off – go to File>New>Other then in the tree list, find the “Checkout project from SVN” item under the SVN folder – then click Next.

  2. Next you want to create a new repository location – so select that radio button and click Next.
  3. At this point you can enter in the SVN URL of your choice. The public repository is at: http://gcc.gnu.org/svn/gcc

  4. If you have commit rights, you can enter in the ssh connection address. Eclipse with then clarify you connection information. Eclipse uses the system's SVN implementation, so anything that you can do from the command line should also be possible.
  5. Once you have entered the ssh information Eclipse will connect the the repository and give you a list of branches. You can pick which ever is appropriate – or the head.
  6. Eclipse will then ask what sort of project it is. Select Linux Makefile.
  7. Now Eclipse will check the source. This can take a while.

Setup the source filters, and output directory, and make targets

Once Eclipse has retrieved all the sources from SVN, you should add some filters to the source tree to make things run a little smoother.

  1. Go to the project properties right-click on your project folder> Properties.

  2. Select the C/C++ project paths.
  3. Add the gcc folder to the sources list.
  4. then add exclusions for the test cases folders (so that they are not in the index) and everything you are not going to use.

Next you need to setup how gcc is built.

  1. Make a directory in the workspace (with the shell if you want).
  2. In properties again, go to C/C++ Make Project.
  3. In the build output entry, change it to the location of the folder you just made.
  4. In the Makefile targets you can add the targets that you would normally use. For example: "all-stage1-gcc" and "clean-stage1-gcc"
  5. If you have a multiprocessors machine: change the default make command to "make -jX" where X is the number of build threads you want.

Run the external configure script

This step is easiest to complete outside of Eclipse. You need to run the gcc configure script to generate the make files to build gcc with. Do this in the build directory that you specified for your project. When configure is finished, there should be some make files that CDT will be able to execute.

Building and Running

The way CDT works with the gcc build system is simple: it invokes the make commands, then captures the output and parses it. Then warning and error information is generated and applied to your project.

Trigger a build

To trigger a build, you can do so manually through the Project menu. If you want, the build can be run every time you save a file, to do that, enable the "build automatically" entry in the project menu. Finally, you can also trigger a clean build from the Project menu. In the project settings you can define what make targets you want to be invoked for each of these build options. Setting up run profiles CDT can run your program in a terminal window or attach itself to your program running in gdb and act at a GDB front end. xgcc runs and debugging Eclipse provides facilities to run programs. You can create a profile for each program you run, with location, arguments, and logging and input information.

  1. Open the run dialog Run>Open Run Dialog...

  2. Select C/C++ application, then click new, and name the run profile.
  3. Click browse, then navigate to the xgcc, or cc1 or whatever you want to run or debug in the build folder that you made earlier.
  4. The second tab of the run dialog allows you to add some arguments for the programs execution. The third tab allows you to set any environment variables that will be set during the run. The fourth tab allows you to choose the debugger to use when you run this profile in debug mode, and a gdbinit script if needed. The final tab allows you to redirect the output to a file.

Once you have created a run profile, eclipse automatically adds an entry to run the same thing in the debugger. Click the run or debug buttons to run or debug your code with the current profile.

Test Runs

You can also run the test suites in a run profile. Just select make as the program to run, change to the appropriate working directory and add the arguments that you would normally use to test.

Commiting your changes

The code formatter

CDT comes with a GNU style code formatter. Unfortunately in the CDT4.0 release it does not follow the GNU standard very closely, so any code that you use on it will probably be more messed up than what you started with. There are plans to fix this by CDT4.1.

Committing changes

When you have finished your changes, and gotten the necessary approval you can check into the repository. Once thing you should be careful of is the few extra files of metadata that Eclipse leaves in the source tree. Typically files that get added are a .cproject (CDT's meta data), and .project and sometimes a .settings directory. Be sure when you commit to not add these files to the repository as they are specific to your setup. Alternatively, add these files to your .svnignore file. To submit files, go to the synchronization perspective. Click Synchronize. This will create a list of all the changes you have made, and all the changes in the repository that need to be applied to your files before you can commit. You can then resolves these changes and commit.

Cool Features

This section lists a few cool features in Eclipse that make working on gcc easier.

Hold down the ctrl key, then click almost any element in your code, you will be taken to the definition. Selecting alt+left or alt+right moves you back and forward in your navigation history, just like in a web browser.

Type Browser

hitting ctrl+shift+t brings up the type browser. This allows you to search (with simple regular expressions) for any type in the system. hitting ctrl+o brings up the file outline, where you can search with patten matching for things in the local file

File Browser

ctrl+r opens the resource browser, this is a fast way to find files.

Working Sets

If you work on a small subset of files regularly - make a working set: Window>Working Sets> Edit. This allows you to restrict most operations (like searching etc) to just the files in the working set.

Call Hierarchy Browser

If you right click on any function call and select open call hierarchy - Eclipse can show you the list of function that call this one, and all the functions this

Team Framework

Eclipse has a powerful collaboration framework, which allows you to work with versioning systems. Every facet of version control can be done from Eclipse. Eclipse can do things like head-to-head comparisons of different versions of files - or even three way comparisons. Allow you to browse the repository. And Eclipse even maintains a detailed local history of every change you have ever made to all the files in your workspace.

Code bookmarks

Eclipse allows you to put bookmarks on code, then review them and visit the code. Right click in the gutter, and click bookmark to make a new one.

SVN Diffs in the gutter

enable the "quick diff" setting in the settings menu, and Eclipse will add colored regions in the gutter where you code differs from the current svn copy. This is a fast way to remember where you have been editing.

TODOs FIXME and the Eclipse Task List

If you add a comment in your code that contains "TODO" or "FIXME" these are added to the Eclipse task list. They can then later be reviewed, checked off, and filtered.

Further Reading:

There is almost nothing during regular development that you can't do inside of Eclipse. Most of the time it is just a matter of figuring out how. The CDT wiki is often a good place to start. But poking around often gets the job done too.

None: GCCinEclipse (last edited 2008-05-29 19:39:41 by LaurynasBiveinis)