Saturday 15 November 2014

How to install gcc in Windows


gcc installation on Windows:

gcc is a C compiler implemented by GNU. It is generally available with different flavors of Linux as an inbuilt tool. Now gcc is also available for Windows. MinGW is a project whose goal is to provide runtime, headers and libs to develop window applications using gcc. The official web site of Equation Solution www.equation.com provides gcc compiler for Windows XP (32bit) and Windows 7/8 (64bit) as separate builds. The latest versions of MinGW gcc implement ISO/IEC C11 standards.
Now we will see step by step procedure of installation and usage of MinGW gcc on Windows.
Installation:
Step1: open the site of “Equation Solutions” by clicking on the link ww.equation.com
Select Home – Programming tools – FORTRAN, C, C++ from Navigation Tree
download link of mingGW gcc
Step2: Go down to the page and select proper gcc build according to your platform that is gcc 32bit for Windows XP or gcc 64bit for Windows 7/8.
different builds of mingGW gcc
Step3: Create an installation folder (c:\MinGW)
Step4: Double click on downloaded “gcc setup executable file”
installation of gcc
Step5: Accept the agreement
gcc agrement
Step6: Select “Browse” to select installation folder (Example: c:\MinGW) and  Select “install” to proceed installation in the selected folder c:\MinGW
gcc installation
Step7: Select “finish” to complete installation
finishing installation

Executing C program using gcc:

Step1: Open the text editor “Notepad” by selecting start button, typing notepad in command text field and press enter. In case of Windows XP select start – select run – type notepad – select open
opening notepad in windows 7
Step2: Type the program in the text editor (notepad)
1
2
3
4
5
6
7
8
9
#include
void main()
{
int x,y,z;
x=10;
y=20;
z=x+y;
printf("Sum of two numbers: %d",z);
}
simple c program
Step3: Save the program with .c extension under a particular directory by selecting file – save. Here, I am saving under d:\demo as first.c
saving c program
Close the editor by selecting file – exit
Step4: Open the command prompt to compile and execute the program by selecting start button, typing cmd in command text field and press enter (¿). In case of Windows XP select start – select run – type cmd – select open.
opening command prompt in windows 7
Step5: Compile the program using the C compiler gcc. The compiler translates the source code and produces equalant executable code with the name a.exe (produces a.out in case of Linux). It can be executed by giving its name directly at the command prompt.
d:\>cd demo
d:\demo>gcc first.c
d:\demo>a
gcc on windows
Here there is a problem with the executable file a.exe because the output of gcc for every C program is a.exe. The executable code of current program overwrites the executable code of previous program compiled. If we want to execute the previous program then need to be recompiled.
We can produce different executable files with different names by sending parameter –o to gcc while compiling.
The general form of –o parameter is
Syntax of gcc
d:\>cd demo
d:\demo>gcc -o first first.c
d:\demo>first
gcc on windows
Here option –o generated the executable file with the name “first.exe” instead “a.exe”. It is executed by giving its name at terminal prompt. Like wise we can generate different executable files for different C programs.

No comments:

Post a Comment