In this tutorial, you will learn how to install MinGW on Windows to run your first C program in the command prompt through the GCC compiler.
Table of Contents
Before proceeding with the installation let’s discuss briefly what is GNU, GCC, and MinGW along with their differences to get a clear idea.
GNU
GNU, which stands for “GNU’s Not Unix”, is a Unix-like operating system and a collection of free software tools beyond just compilers that are designed to develop software programs.
Think of GNU as an all-inclusive travel kit designed for a global adventurer. This kit isn’t just any travel kit. It includes everything from maps and guidebooks to tools like compasses and multi-tools, equipping you for various travel needs and unexpected situations. In software terms, GNU provides a comprehensive set of free tools designed to support software development across different environments.
GCC
GCC stands for GNU Compiler Collection. It is a piece of GNU software that includes a compiler with frontends for multiple languages like C, C++, Java, Ada, Fortran, etc.
GCC is similar to a multi-language phrasebook in your travel kit. Just as a phrasebook allows you to communicate in multiple languages, GCC supports compiling in multiple programming languages such as C, C++, and Java. This versatility is crucial because it lets developers “speak” the right programming language for their specific project’s needs, just like using the correct language in a foreign country.
MinGW
Finally, to run GCC on Windows, you need a port of GCC that is compatible with the Windows operating system. MinGW (Minimalist GNU for Windows) provides such a port, allowing developers to use GCC and other GNU tools to compile and run native Windows applications. It contains everything needed for linking and running your code on Windows. MinGW includes a port of the GNU Compiler Collection (GCC), assembler, linker, etc. MinGW is a compiler system based on the GNU GCC and Binutils projects that compiles and links code to be run on Windows. It provides C, C++, Fortran compilers, and other related tools.
MinGW acts like a travel adapter, allowing you to use your electronic devices in countries with different electrical outlets. Similarly, MinGW adapts GNU tools and the GCC compilers to work seamlessly on Windows, enabling developers to use their familiar GNU tools to create applications native to the Windows environment. This adaptation ensures that you can still use those tools effectively in Windows.
![](https://syntaxscenarios.com/wp-content/uploads/2024/05/mingw-components-1024x576.png)
Install MinGW on Windows
To install MinGW on Windows, go to https://sourceforge.net/projects/mingw/ and click on the Download Button.
![Install MinGW on Windows: Step 1](https://syntaxscenarios.com/wp-content/uploads/2024/03/1-1024x321.jpg)
When the download is complete, click the .exe file. Then click on Install.
![Install MinGW on Windows: Step 2](https://syntaxscenarios.com/wp-content/uploads/2024/03/2.jpg)
The default installation directory is C:\MinGW. You can click on Change to change the installation directory. Then click on Continue.
![Install MinGW on Windows: Step 3](https://syntaxscenarios.com/wp-content/uploads/2024/03/3.jpg)
When the MinGW installation is complete, click on Continue.
![Install MinGW on Windows: Step 4](https://syntaxscenarios.com/wp-content/uploads/2024/03/4.jpg)
Now we will install the basic GCC Compiler for C by clicking on the mingwn-base checkbox and clicking on mark for installation. Then click on installation and click Apply Changes.
![Install MinGW on Windows: Step 5](https://syntaxscenarios.com/wp-content/uploads/2024/03/5-1024x513.jpg)
Click on Apply.
![Install MinGW on Windows: Step 6](https://syntaxscenarios.com/wp-content/uploads/2024/03/6.jpg)
When the MinGW installation is complete, click on Close.
![Install MinGW on Windows: Step 7](https://syntaxscenarios.com/wp-content/uploads/2024/03/7.jpg)
Now we will add the path to MinGW to system environment variables so that we don’t have to give the full path to the GCC compiler when we run the compiler from the command prompt. Use the following steps to add the path to MinGW to system environment variables:
Type environment variables in the search bar of Windows and click on edit the system environment variables.
![Install MinGW on Windows: Step 8](https://syntaxscenarios.com/wp-content/uploads/2024/03/8.jpg)
Click on the environment variables.
![Install MinGW on Windows: Step 9](https://syntaxscenarios.com/wp-content/uploads/2024/03/9.png)
From the system, variables click on the Path and select Edit.
![Install MinGW on Windows: Step 10](https://syntaxscenarios.com/wp-content/uploads/2024/03/10.png)
Click on New to add a new path.
![Install MinGW on Windows: Step 11](https://syntaxscenarios.com/wp-content/uploads/2024/03/11.png)
Paste the path to the bin folder where your GCC compiler is located. It is located inside the bin folder of MinGW.
![Install MinGW on Windows: Step 12](https://syntaxscenarios.com/wp-content/uploads/2024/03/12.png)
Check if MinGW has been Installed Successfully
Open the command prompt and type gcc –version
to check if the GCC is successfully installed and working.
![](https://syntaxscenarios.com/wp-content/uploads/2024/03/13-1024x591.png)
Compile and run your first C program through Command Prompt
Now open notepad and paste the following code:
#include <stdio.h> int main() { printf("Hello, World!"); return 0; }
- Save your file as program.c (or any name followed by the .c).
- Open cmd and go to the directory where your C program is located. In case the program is located on desktop type:
cd desktop
- To compile your C program into object code, using the GCC compiler type the following command in cmd.
gcc -c source_file_name -o object_file_name
Where the object file name is the name you wish to name the object file after compiling your program.
In our case, we will write:
gcc program.c -c prog
This command will compile your program and create and object file with the name “prog”.
Now to convert the object file into an executable file, use the following command.
gcc prog.o -o p
Where “p” is the name of the executable file.
Now to execute the file simply type the name of the executable file and hit enter.
p
![](https://syntaxscenarios.com/wp-content/uploads/2024/03/14.png)
If you want to create an executable file directly you can use the following command:
gcc program.c
If you don’t specify any name for the executable file, by default its name will be a.
![](https://syntaxscenarios.com/wp-content/uploads/2024/03/15.png)
Pingback: Discover the Best Online Platform for C Programming Tutorials
Pingback: The Ultimate Guide to Learning C Language From Syntax Scenarios - Page Traffic Solution
Pingback: Master C Programming with Syntax Scenarios - Detailed Overview - A Medley of Thoughts and Topics
Pingback: Syntax Scenarios: Where Learning C Language is Free, Fun, and Easy
Pingback: Master C Language with Ease: Explore Free, Fun Learning on Syntax Scenarios - Klighthouse
Pingback: Start Your C Programming Journey Free with Syntax Scenarios – A4Everyone
Pingback: Where to Learn C Language for Free – Nims Trading ltd
Pingback: Guide to Free Learning with Syntax Scenarios - seo
Pingback: Coding Through Engaging Syntax Scenarios
Pingback: Why Syntax Scenarios Tops the List – Platforms for Learning – That AI Blog
Pingback: Build Your Coding Skills for Free with Syntax Scenarios – BizBackLinks
Pingback: Learn Programming With Syntax Scenarios - Blogs Mania