This article is aimed at developers who need to debug or experiment with the GCC source. The open source Eclipse IDE has some interesting features that enable your GCC source to be easily integrated into Eclipse. So, get started!
Before we start, here is some basic information on the software you may need to implement the steps given here for configuring GCC source in the Eclipse IDE.
The steps are explained based on my experience of using Eclipse on Windows. However, the same can be achieved on Linux as well.
For building on Windows, Cygwin must be installed on your system. I assume that you are familiar with the tools required for a GCC build (gcc, gdb, make and the associated libraries) and the GCC build process. To refresh the GCC build basics, visit http://gcc.gnu.org/install/
For this article, I used GCC 4.6.2, but the same steps are applicable to any version.
Steps to configure GCC source in the Eclipse IDE
Step 1: Downloading and installing Eclipse. Get Eclipse from http://www.eclipse.org/downloads/, which offers several versions; you can use any for C or C++ development. My favourite, and the one used for this article, is Eclipse Indigo for C/C++ developers, which contains in-built CDT support. Installation is simple: just extract the tar/zip archive to the desired location and start using the contained Eclipse application.
Step 2: Creating a workspace. When you start Eclipse, it will prompt you to select a workspace. Specify any name; I chose to use Workspace_GCCBuild.
Step 3: From the Eclipse home screen, click the Workbench option, and an empty workspace will be created.
Step 4: Creating a project. Now, you need to add a project. Click File->New->C Project. Give a name to the project; it should be a Makefile project with the Cygwin GCC tool-chain, as shown in Figure 1. (I repeat, this option will be visible only if Cygwin is installed on your system.) This will open up an empty project.
Step 5: Project settingsmake sure Build Automatically is selected in the Project menu, as shown in Figure 2.
Step 6: Using the file manager (Explorer), place the extracted GCC source folder (e.g., gcc-4.6.2) in the folder created for your project. Now, refresh the workspace in Eclipse by pressing F5. The source is displayed in the Project Explorer, as shown in Figure 3.
Step 7: Now, you need to see how to compile the source. This part is a bit tricky. For this, create a .bat batch file containing the configure command, as shown below:
sh ../gcc-4.6.2/configure –enable-languages=c
Note: As mentioned earlier, I assume you’re familiar with the GCC build process. Here, we are building GCC for native.
Add this .bat file to your project folder (at the same level as the GCC source folder), and refresh the workspace, before checking that it’s shown.
Step 8: Next, register this batch file as an external tool. For that, go to
Run->External Tools->External Tools Configuration. Now, specify a name for the external tool. Click Browse Workspace and select your batch file from the listing for the Location field. Specify your project directory as the working directory (see Figure 4). Now, hold your breath, and click Run. Voilà, your code has started compiling!
So, all it takes is 8 simple steps to build GCC source using the Eclipse IDE. It is even more interesting to debug your GCC code using Eclipse. Watch out for my next article to learn more about that!