How To Install MinGW on Windows

C++
By bhagwatchouhan
How To Install MinGW on Windows

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 with mingw-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 mingw-w64. It will show various download options as shown in Fig 1.

MinGW Download

Fig 1

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.

MinGW Download

Fig 2

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.

MinGW-W64 Welcome

Fig 3

Click on the Next Button to continue with the installation. It will show the settings screen as shown in Fig 4.

MinGW-W64 Settings

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 posix option of Threads settings for programs involving multithreading. You may select the win32 option based on your needs. Now click on the Next Button to continue with the installation. The next screen asks for the installation path as shown in Fig 5.

MinGW-W64 Installation Path

Fig 5

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.

MinGW-W64 Downloading

Fig 6

MinGW-W64 Download Progress

Fig 7

MinGW-W64 Downloaded

Fig 8

Now click on the Next Button after download completes. It will show the success message as shown in Fig 9.

MinGW-W64 Installed

Fig 9

Click on the Finish Button to close the installer. Now add the bind directory of MinGW-W64 to the system path as shown in Fig 10.

MinGW-W64 System Path

Fig 10

 

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.

MinGW Welcome

Fig 11

Click on the Install Button to start the installation. It will ask for the installation directory as shown in Fig 12.

MinGW Installation Path

Fig 12

Click on the Continue Button to start the installation. It will show the progress as shown in Fig 13 and Fig 14.

MinGW Installation

Fig 13

MinGW Downloaded

Fig 14

Click on the Continue Button to launch the installation manger as shown in Fig 15.

MinGW Installation Manager

Fig 15

Choose the package GCC as shown in Fig 16.

MinGW Installation Manager GCC

Fig 16

Click on the Apply Button to apply the changes as shown in Fig 17.

MinGW Installation Manager Apply

Fig 17

Click on the Apply Changes Button. It will show the confirmation message as shown in Fig 18.

MinGW Installation Manager Package

Fig 18

Click on the Apply Button to install GCC. It will show the Package progress as shown in Fig 19 and Fig 20.

MinGW Installation Manager Progress

Fig 19

MinGW Installation Manager Finish

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.

MinGW C Output

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.

MinGW C++ Output

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.

Share this blog:

Profile picture for user bhagwatchouhan
bhagwatchouhan