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:
- Install the latest version of JDK by downloading from www.oracle.com – downloads
- 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.
- 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)
→ Create short-cut to eclipse by right click on eclipse icon – select send to – select desktop (Create shortcut)
→ Open the eclipse by double click on eclipse icon
→ Select the d:\practice as your workspace folder and select OK while loading eclipse for the first time
→ A welcome page to the eclipse IDE for C/C++ development appears, select “work bench”
Configuring preferences in eclipse:
→ Select Window – preferences
→ Select General – Workspace – UTF-8 under Text file encoding – UNIX under New text file line delimiter – select Apply
→ 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.
→ Select c/c++ – New CDT project wizard to set the default tool chain to compile
- 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
→ Give the project name (codingfox)
→ Select finish
→ Add a C program under the project by right click on project (codingfox) in the project explorer – new – C source file
→ Give the source file name (hello.c) – select finish. Make sure that the file name must have .c extension
→ Type the program
#include<stdio.h> int main() { printf("Hello World"); return 0; }
→ 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
Why error accurse while making build?
Source file may not be saved