MinGW also called as Minimalistic GNU for Windows is a popular compiler for C and C++ and used for the development of native MS-Windows applications. It does not depend on any 3rd party tools or libraries but relies on the several DLLs provided by Microsoft as components of the operating system. Out of these DLLs, MSVCRT.DLL i.e. Microsoft C runtime library is the primary one. Apart from the system components, the threaded applications must use freely distributable thread support DLL, provided as part of MinGW itself. You may consider using Cygwin for POSIX application deployment.
Below listed are the features and components provided by MinGW. You may also refer MinGW for more details.
- A port of the GNU Compiler Collection (GCC), including C, C++, ADA and Fortran compilers;
- GNU Binutils for Windows (assembler, linker, archive manager)
- A command-line installer, with optional GUI front-end, (
mingw -get) for MinGW and MSYS deployment on MS-Windows - A GUI first-time setup tool (
mingw -get-setup), to get you up and running withmingw -get.
In this tutorial, we will install MinGW on windows and write, compile, and execute our Hello World program in C++.
Step 1: Download MinGW
Go to the Download Page to start downloading
Download MinGW-W64-builds as highlighted in Fig 1.
You may also download and install MinGW Installation Manager in case you are planning only for the 32-bit compiler. The MinGW-W64 provides both 32-bit and 64-bit compilers.
Download MinGW Installation Manager as highlighted in Fig 2.
Step 2: Install MinGW-W64
Now execute the MinGW-W64-builds executable downloaded by us in the previous step. It will show the welcome screen as shown in Fig 3.
Click on the Next Button to continue with the installation. It will show the settings screen as shown in Fig 4.
Note that I have selected x86_64 architecture in order to support 64-bit instructions. You may continue with i686 for 32-bit instructions. Also, I have selected the
Make sure that you provide an installation path without any spaces. Now click on the Next Button to finish the installation.
It might show you error specific to fail to download. I tried a few times and got success in 3rd attempt. You may also continue with manual installation in case it failed multiple times. You can simply download the archive of MinGW-W64 and extract it to the desired location.
It will show the download progress and status as shown in Fig 6, Fig 7, and Fig 8.
Now click on the Next Button after download completes. It will show the success message as shown in Fig 9.
Click on the Finish
Step 3: Install MinGW
In this step, we will install the MinGW distributed by the official website as shown in Fig 2. Execute the installer downloaded in previous steps. It will show the welcome screen as shown in Fig 11.
Click on the Install Button to start the installation. It will ask for the installation directory as shown in Fig 12.
Click on the Continue
Click on the Continue Button to launch the installation manger as shown in Fig 15.
Choose the package GCC as shown in Fig 16.
Click on the Apply
Click on the Apply Changes
Click on the Apply Button to install GCC. It will show the Package progress as shown in Fig 19 and Fig 20.
Click on the Close Icon and also close the installation manager to complete the installation of the compiler required to compile the programs.
You may add the MinGW path to bin directory which is C:\cpp\mingw\bin in my case to system path as we did for MinGW-W64. Make sure that you keep only one compiler path at a time among MinGW and MinGW-W64.
Step 4: Getting started with C - Hello World
Write your first C program as shown below and save in a file hello.c.
#include<stdio.h> int main() { printf( "Hello World" ); }
Compile and execute the program using the command as shown below.
# Compile and make executable gcc hello.c -o hello.exe
It will compile the program and generate the executable i.e. hello.exe. We can simply type hello to execute the program. It will print Hello World on the console as shown in Fig 21.
Step 5: Getting started with C++ - Hello World
We can repeat the previous step to write the Hello World program in C++. Write your first C++ program as shown below and save it to hello.cpp.
#include<iostream> using namespace std;
int main() { cout << "Hello World"; return 0; }
Compile and execute the program using the command as shown below.
# Compile and make executable g++ hello.cpp -o hello.exe
It will compile the program and generate the executable i.e. hello.exe. We can simply type hello to execute the program. It will print Hello World on the console as shown in Fig 22.
This is how we can install MinGW and MinGW-W64 and configure the system path to access the executables from the command line. We also wrote our first C and CPP programs, compiled and executed them to print Hello World on the console.