Installing and Configuring Eclipse for C

You will need write, compile and test C programs during this semester. Any C development environment is acceptable, but I'm the most familiar with using Eclipse with the CDT.  This document explains how to install eclipse on a Windows/Linux/Mac machine.

In order to install Eclipse with the CDT (C/C++ development tools), you have to end up with several pieces of software installed:

Depending on your platform you will need to install some or all of these.  

Installing C/C++ and gdb:


If you've installed the development tools, you should have gcc, g++ and gdb installed.  If not, use the appropriate update utility to find and install these three tools.  You will also need to install Java if you have not previously done so.  If you plan on installing the latest Eclipse (Luna), you will need to have installed at least Java 7.

MacOS X:

The C and C++ compilers are installed as part of XCode.  You can find a pretty good explanation of how to install the compilers at this location: Installing the GNU compilers on Mac OS X.  For the purposes of this course, you don't need to install the latest and greatest gcc from the HPCC -- you can stop after you use xcode to install an initial version.

Unfortunately, with Mac OS X Mavericks, Apple has discontinued shipping gdb with the developer tools.  This page does a pretty good job of explaining how to use homebrew to install gdb.  Don't forget to follow the link to codesign gdb once you've installed it.


The easiest way to get all three of C, C++ and gdb installed is by installing the cygwin environment.  Instructions on installation can be found here.

Phew... so now you have C, C++ and gdb installed.

Installing eclipse (optional):

Testing your CDT:

Every C program is a "project" in eclipse terms. So, let's create a Hello world program:

New C Project dialog box

You'll need to give your project a name ("HelloWorld" above), and select a project type.  Notice that I've selected Empty Project.  I've also selected the correct toolchain for my platform - MacOSX GCC.  You will most likely only have one tool chain to choose from, but if you have multiple, pick the one with gcc in its name.  Press "Finish"

Your project will now be created and show up in your project explorer view. 

#include <stdio.h>

int main(int argc, char ** argv)
    printf("Hello cruel world!\n");

Once you've typed this in, select File->Save (or CTRL-S).  

16:26:17 **** Build of configuration Debug for project HelloWorld ****
make all
Building file: ../hello.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"hello.d" -MT"hello.d" -o "hello.o" "../hello.c"
../hello.c:12:32: error: expected ';' after expression
        printf("Hello cruel world!\n")
1 error generated.
make: *** [hello.o] Error 1

16:26:17 Build Finished (took 163ms)

From this text, you'll notice I had an error -- that I was missing the ; in my printf line.   You can also find more friendly reports of any errors in the Problems section.  Find and fix any errors and re-run the build:

16:27:53 **** Incremental Build of configuration Debug for project HelloWorld ****
make all
Building file: ../hello.c
Invoking: GCC C Compiler
gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"hello.d" -MT"hello.d" -o "hello.o" "../hello.c"
Finished building: ../hello.c
Building target: HelloWorld
Invoking: MacOS X C Linker
gcc  -o "HelloWorld"  ./hello.o  
Finished building target: HelloWorld

16:27:53 Build Finished (took 268ms)

Hello cruel world!

You now have a working C environment with your Eclipse.  Congratulations!