Installing Eclipse for C/C++ and MinGW

PICTURES COMING SOON!

Whether you’ve just decided to learn C/C++ or you’ve been developing for years, using an IDE (Integrated Development Environment) can make your life so much easier. IDEs offer many helpful features, from color-coded syntax to in-line debugging auto-complete features.

Netbeans has typically been my go-to IDE. However, many developers prefer Eclipse for its open-source roots and large collection of plugins. However, installing Eclipse can be a bear, especially for those new to the development world. Therefore, I decided to write up a quick tutorial that worked for me.

NOTE: This tutorial is based on Windows 7, though installations on other previous versions of Windows is likely to be the same or very similar.

A PREREQUISITE
Eclipse is a java-based program. Even if you don’t want to develop in Java, Eclipse will need a JVM (Java Virtual Machine) to work. If you’re new to these terms, don’t fret; it’s not complicated! You have two options. First, you can simply install the Java Runtime Environment (or JRE) by going to http://www.oracle.com/technetwork/java/javase/downloads/index.html. Otherwise, if you want to develop in Java, visit the same link to find the Java Development Kit (JDK) download. At any rate, the installation process is fairly straightforward. Continue on once you have Java installed on your machine.

DOWNLOAD ECLIPSE
The first thing you need is the Eclipse download file from http://www.eclipse.org/downloads. Look down the list for “Eclipse IDE for C/C++ Developers” and find the Windows 32 Bit/Windows 64 bit links on the right. Make sure you choose the version that matches your operating system! If you’re unsure whether you have 32- or 64-bit, look under Control Panel>System and Maintenance>System.

After clicking the link, you’ll be taken to a Download – Mirror Selection page. Choose any mirror (the first listed will be fine) to begin the download. Notice that the download is a zip file and NOT an exe. This is where many people become confused. There is no installer for eclipse!

INSTALLING ECLIPSE
Don’t let my previous statement worry you. The next steps are REALLY easy. Unzip the download file to your “C:\Program Files” directory, then open the eclipse folder and find the eclipse.exe file. This is Eclipse. Double-clicking will open, but I suggest creating a shortcut on your desktop or pinning it to your Start menu for easier access. See, I told you it was easy. However, there are a few more things you need to do before you can actually create C applications.

NOTE: If Eclipse warns you that it can’t find Java, you may have to add your JRE/JDK to your PATH environment variable. It’s very easy, just google something like “Add Java to PATH.”

INSTALL MinGW
Programs written in C must be compiled into machine language before they can be run. However, Eclipse w/ C/C++ does not come prepackaged with a set of compilers, so unless you already have one installed on your computer, you’ll need to follow this step. There are multiple options when it comes to compilers, but MinGW is one of the top recommended for Windows machines – and it’s what I use!

First, download MinGW at link. Second, run the installer. During the installation, you will be asked which components you would like to install. “C Compiler” will automatically be selected, but feel free to add others as you wish.

Third, you will need to make sure that MinGW is added to your PATH. Basically, just append “C:\MinGW” to the end of the path (unless you specifically changed the location during the installation). Finally, open Eclipse and test by creating a new C project to build and run. If you already know what you’re doing, good luck and thanks for reading! Otherwise, continue to the next section on creating a simple C project in Eclipse.

HELLO WORLD IN ECLIPSE
Follow these steps to create a simple Hello World project in Eclipse:

    File>New>C Project. Give the project a name (like “helloWorld”), choose “Empty Project” in the Project Type box and “MinGW GCC” in the Toolchains box, then click Finish.
    You should see your new project listed in the Project Explorer pane on the left. Right-click on the project, then choose New>Source File. Give the file a name (like “main.c”), but make sure you type the “.c” extension. Then click Finish.
    In your new file, type the following code:


#include <stdio.h>;
int main() {
printf("Hello C Programmers!");
return 0;
}

    Now build your application by right-clicking on the project and choosing “Build Project”. Keeping my fingers crossed that I have not left out any steps, you should not receive any errors in the console at the bottom.
    Finally, run your program by right-clicking on the project and choosing Run As>Local C/C++ Application.

If that worked and you saw the message printed to the console, then congratulations! You have successfully installed Eclipse/MinGW and built your first program! Have fun and let me know if you have any questions.

Chris

About these ads

6 responses to “Installing Eclipse for C/C++ and MinGW

  1. thanks

  2. I followeed as said above. But when I run the application I get this error stating “Launch failed. Binary not found”. Can you please help me solve this error.

  3. thanks a lot. after a frustrating day of trying to dual boot my new laptop i had to give up temporarily to setup a windows dev environment. this helped out a lot!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s