1.10 – How to execute a C program in eclipse

by subbu on August 4, 2013

Eclipse is open source software used to develop applications in different platforms. It is the most commonly used development software by individuals and organizations in the industry. Eclipse foundation provides a separate tool called “Eclipse IDE for C/C++ Developers” for C and C++ application development. It is available for different operating systems like Windows, Linux and MAC as separate builds for 32bit and 64bit systems. Because eclipse is developed in java, it is mandatory to install Java Runtime before installation of eclipse on any system. Eclipse doesn’t provide C/C++ compilers with IDE. Any flavor of Linux is pre-loaded with gcc (C compiler) and g++ (C++ compiler). Hence eclipse IDE uses these tools to compile C and C++ programs under Linux environment. If in case of Windows environment, we need to install MinGW pack for eclipse.

Installation of eclipse in windows for C/C++ application development:

  1. Install the latest version of JDK by downloading from www.oracle.com – downloads
  2. Install the latest version of MinGW for C/C++ as covered in the previous session. Make sure that, MinGw pack must be installed in c:\MinGW, otherwise eclipse can’t identify MinGW.
  3. Download the “Eclipse IDE for C/C++ Developers” zip file from www.eclipse.org/downloads/ and extract it into the required folder.

Configuring eclipse for MinGW:

→ Create your workspace folder to store all the projects at one place (d:\practice)

workspace directory

 Create short-cut to eclipse by right click on eclipse icon – select send to – select desktop (Create shortcut)

creating shortcut to eclipse

→ Open the eclipse by double click on eclipse icon

shortcut to eclipse

 Select the d:\practice as your workspace folder and select OK while loading eclipse for the first time

selecting workspace directory

→ A welcome page to the eclipse IDE for C/C++ development appears, select “work bench”

welcome page to eclipse

Configuring preferences in eclipse:

 Select Window – preferences

preferences in eclipse

 Select General – Workspace – UTF-8 under Text file encoding – UNIX under New text file line delimiter – select Apply

workspace configuration

 Select c/c++ – Editor – Folding – select enable folding of preprocessor branches and control flow statements – uncheck all the options under Initially fold these region types.

folding in eclipse

 Select c/c++ – New CDT project wizard to set the default tool chain to compile

CDT settings in eclipse

CDT in eclipse

  • Make sure that Empty Project is selected under Executables
  • Select MinGW GCC under Toolchains
  • Select Make toolchains preferred button
  • Make sure that preferred toolchaine(s): MinGW appears.

Executing a C program in eclipse:

 Select File – New – C project

c-project

→ Give the project name (codingfox)
 Select finish

C project in eclipse

 Add a C program under the project by right click on project (codingfox) in the project explorer – new – C source file

new source file

 Give the source file name (hello.c) – select finish. Make sure that the file name must have .c extension

creating C source file in eclipse

 Type the program

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

c program in eclipse
 Build the binary code by selecting Project – Build All (Ctrl+B)

 Execute the program by selecting Run – Run (Ctrl+F11)

Why MinGW GCC is not displaying under Toolchains?

If MinGW GCC doesn’t appear under Toolchains then it means eclipse doesn’t recognize MinGW. Make sure that MinGW is installed only under c:\MinGW (c:\MinGW\bin\gcc.exe)

Why binary not found error accurse?

Trying to compile without making build. Make sure that Ctrl+B is selected before Ctrl+F11

binary not found error in eclipse

Why error accurse while making build?

Source file may not be saved

Previous post:

Next post: