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.
Don’t click the “Download” button on the next page. Instead click the “Download Packages” link.
Scroll down to “Eclipse IDE for C/C++ Developers”.
Click the download link for the platform you are using.
Installing Eclipse
You’ve downloaded Eclipse. Congratulations! Time to install it.
Installing Eclipse on a Mac
On a Mac, the download will be a “.dmg” disk image. It will probably be in your Downloads folder.
Double-click it to “mount” the image.
A Finder window should open displaying the Eclipse application and a shortcut to the Applications folder.
To install Eclipse in the Applications folder, just drag the application onto the shortcut. You may need administrator privileges for this.
But Eclipse can be installed anywhere, such as your Desktop or any other folder. Just drag it from the mounted disk image to where you want it.
To unmount the disk image, click the eject button in a Finder window siderbar (if it is shown there), or drag the disk icon that is on your desktop to the Trash.
You can delete the “.dmg” file once you’ve put Eclipse where you want it.
Installing Eclipse on Windows
On a Windows machine, the download will be a “.zip” archive. It will probably be in your Downloads folder.
Double-click it to extract (unpack) the archive.
You can run Eclipse right from the resulting folder, or move it somewhere else.
You can delete the “.zip” file once you’ve unpacked it.
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.
Windows: Install MinGW (“Minimal GNU for Windows”) or Cygwin (“a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.”)
Linux: Use your package manager to install (at least) the “gcc,” “gdb,” and “make” packages
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
File > New > C/C++ Project...
Select “C Managed Build” then click Next
Enter project name (whatever you want, e.g., “Hello World Project”)
Project type: Executable > Empty Project
Select the toolchain for your platform:
macOS: MacOSX GCC
Windows: MinGW GCC
Linux: ?
Add a C source file to the project
File > New > Source File
Enter filename for new file, e.g., “hello.c”
Note that this does not use a “src” folder as you may be used to seeing with Java development using Eclipse. Simply adding a folder and using it doesn’t Just Work, but I’m sure it could be made to work if you really wanted a “src” folder.
Change compiler settings for the project
This is REQUIRED FOR CSC173!
Select the project in the Eclipse Project Explorer
Then select Properties from the File menu to show the project properties
In the Project Properties pane: select C/C++ Build > Settings
Select the “Tool Settings” tab
Select GCC C Compiler > Dialect
Then select “ISO C99 (--std=c99)” from the “Language standard” menu
“-std=c99” is REQUIRED for CSC173
Select GCC C Compiler > Warnings
The default project has “All warnings (-Wall)” checked
Also check “Warnings as errors (-Werror)”
Both “-Wall” and “-Werror” are REQUIRED for CSC173
Click “Apply and Close”
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:
Select the project in the Eclipse Project Explorer
Then select Properties from the File menu to show the project properties
In the Project Properties pane: select C/C++ Build > Settings
Select the “Build Artifact” tab
The default “Artifact name” is “${ProjName}”, which Eclipse will replace with the name of the project
Enter whatever name you want for the executable, e.g., “hello”
Click “Apply and Close”
Running the project's program
Select “Run Configurations...” from the Run menu
From the list on the left, select “C/C++ Application”
Click the button that looks like a rectangle with a “+” sign at the top of that list (its tooltip says “New launch configuration” if you hover over it)
The new run/launch configuration uses the current project and executable by default
I have found that on Windows you may need to specify the executable as, for example, “Debug\hello.exe” where “Debug” is the name of the build configuration and “hello.exe” is the executable filename with the standard extension for executable files. Your mileage may vary.
Click “Close”
From now on you can run the project by clicking the green and white “Play” button just like for a Java project
Exporting a project as a ZIP archive
You probably already know how to do this, but just in case...
Select the project in the Eclipse Project Explorer
Select “Export...” from the File menu
Select General > Archive File then click “Next”
Make sure that all and only the resources that you want to export are checked.
For CSC173: You would NOT normally include any compiled object or executable files in your submissions. Just the source files and your README.txt (and a Makefile if you use one).
Next to “To archive file:” use the “Browse” button to specify where the archive file should be created
Click “Finish” to create the archive
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:
Select “Import...” from the File menu
Select General > Existing Projects into Workspace, then click “Next”
Check “Select archive file” and use the “Browse” button to find the file to import