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.
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
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.
Step3: Create an installation folder (c:\MinGW)
Step4: Double click on downloaded “gcc setup executable file”
Step5: Accept the agreement
Step6: Select “Browse” to select installation folder (Example: c:\MinGW) and Select “install” to proceed installation in the selected folder c:\MinGW
Step7: Select “finish” to complete 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
Step2: Type the program in the text editor (notepad)
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
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.
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
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
d:\>cd demo d:\demo>gcc -o first first.c d:\demo>first
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.