How to setup Eclipse for C/C++ programming in Windows with MinGW

For C/C++ programming you can use IDEs like Visual Studio and Eclipse. While downloading and setting up Visual Studio is straight forward, the eclipse installation has some manual steps. For Eclipse, you would need to download C/C++ CDT.

The C/C++ Development Toolkit (CDT) is a collection of Eclipse-based features that provides the capability to create, edit, navigate, build, and debug projects that use C and/or C++ as a programming language.

The CDT does not include the necessary compilers and debuggers to convert C/C++ code into executable programs and to debug those programs, but it does provide the frameworks that allow such tools to be integrated in a consistent fashion. This allows you to mix and match such tools depending on your project requirements.
 

How to install Eclipse C/C++ Development Tool (CDT)

Two ways to install CDT, depending on whether you have previously installed an Eclipse:

  • If you have already installed “Eclipse for Java Developers” or other Eclipse packages, you could install the CDT plug-in as follows:
    Launch Eclipse ⇒ Help ⇒ Install New Software ⇒ In “Work with” field, pull down the drop-down menu and select “Kepler – http://download.eclipse.org/releases/kepler” (or juno for Eclipse 4.2; or helios for Eclipse 3.7).
    In “Name” box, expand “Programming Language” node ⇒ Check “C/C++ Development Tools” ⇒ “Next” ⇒ … ⇒ “Finish”.
    install eclipse cpp
  •  

  • If you have not install any Eclipse package, you could download “Eclipse IDE for C/C++ Developers” from http://www.eclipse.org/downloads, and extract the downloaded file into a directory of your choice.

 

How to Install the MinGW Tools for C/C++

I downloaded the MinGW from this url and followed the setup instructions ..

https://www.rose-hulman.edu/class/csse/resources/MinGW/installation.htm

You may also download and setup a latest copy from the MinGW website :

http://www.mingw.org/

 

Writing First C Program with Eclipse

Create a new project

Go to File → New → C Project, and choose a name for the project (for example, HelloWorld).

In the Project type pane, expand Executable and select Hello World ANSI C Project.
In the Toolchains pane, select MinGW GCC.

eclipse setup for c

Click Finish to accept all defaults.

 

HelloWorld.c

The above step should have created a file HelloWorld.c inside the project.

It should have some code like this :

/*
 ============================================================================
 Name        : HelloWorld.c
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

int main(void) {
  puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
  return EXIT_SUCCESS;
}

You can modify the program logic now.. for this article, lets keep the same code and try to run the project.

 

Build, compile, and run the project

Right-click the project and select “Run As → Local C/C++ Application”.

You should now see following message in Console :


!!!Hello World!!!

 

Getting error ? “Launch failed. Binary not found”

If you get the “Launch failed. Binary not found” while running the project, you can fix it in following ways :

Simply select the project and press CTRL + B.

(or)

Select the project, then right click and go to Project->Properties->C/C++ Build->Settings->Binary Parsers and select the correct parser.

For example, for MinGW on windows, choose PE Windows Parser checkbox and click ok.

Now, you can run the project again and it should run to success.

 

How to Add an Eclipse Shortcut to Desktop

Open the folder where Eclipse was installated. For example, C:\eclipse.

Right click on the Eclipse application (eclipse.exe) file icon and select “Send to => Desktop (Create Shortcut)”.

This creates a new shortcut in Desktop. Similarly, you can add a shortcut in the start menu or taskbar as well.

 

© 2017, https:. All rights reserved. On republishing this post, you must provide link to original post

Leave a Reply.. code can be added in <code> </code> tags