Using Eclipse for C (in CSC173)

Using Eclipse for C (in CSC173)

George Ferguson

Last update: Summer 2021
(minor edits Summer 2023)

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License
Image

Students are used to using the Eclipse IDE for programming in Java. This document describes how to install and use Eclipse for programming in C (and C++). Amazingly, it isn’t as easy as it should be.

A word of warning to Computer Science students: At some point in your career you are going to need to be able to use the terminal/shell/command-line on your computer (the name varies across platforms). Even if you want to use Eclipse or another IDE for writing code, I strongly suggest that you learn how to build (compile) and run your programs from the terminal.

This document was written for Eclipse 2021-06 and tested primarily on macOS 11.5.1 Big Sur, but also on Windows 10.

Obtaining Eclipse

Installing Eclipse

You’ve downloaded Eclipse. Congratulations! Time to install it.

Installing Eclipse on a Mac

Installing Eclipse on Windows

Installing Java (yes, even for C/C++ Development)

Eclipse is itself written in Java, so you need Java on the machine to run Eclipse.

Update Summer 2021: The downloadable Eclipse packages include a Java Runtime Environment (JRE) suitable for running Eclipse itself. So you no longer need to download and install Java yourself just to use Eclipse for developing in C.

Progress!

Installing a C Compiler

You might reasonably expect that once you installed something named “Eclipse for C/C++ Development” you would be able to develop C (or C++) programs with it. Unfortunately that isn’t the case. In fact, it isn’t the case for Java development either. For Java development, you need to install Java (well, perhaps not since Summer 2021). For C development you need to install a C toolchain.

The short story:

More details and instructions: Installing a C Compiler (for CSC173)

Using Eclipse for C Programming

Finally!

I suggest using a separate workspace for each course, but you can select whichever workspace you like when Eclipse starts or by selecting “Switch Workspace” from the File menu at any time.

Create new Project

Add a C source file to the project

Change compiler settings for the project

This is REQUIRED FOR CSC173!

Rename the executable program built by the project (optional)

By default, Eclipse builds an executable program whose name is the same as the name of the project. That’s fine if your project is named “project1” or something like that, but not so good if the name is longer, contains spaces, etc.

To rename the executable built for the project:

Running the project's program

Exporting a project as a ZIP archive

You probably already know how to do this, but just in case...

Importing a project stored as a ZIP archive

Not that you need to do this very often, but for importing your own or my projects but NOT projects that fell off the back of a truck as you were walking by: