How to install mingw for windows

How to Install GCC/G++ MinGW on Windows


The default compiler for Microsoft Windows is MSVC and it is installed when we install Visual Studio. Despite being a very powerful IDE, I recommend it for almost all situations, some libraries are more practical to work with in a more minimalist environment and this can be achieved using GCC/G++ on Windows.

The package developed by GNU to get you to use gcc/g++ on Windows is MinGW .

In this article we will see how to install on Windows 10 in the most basic and minimalist way possible!

Let’s go step by step!


1. Downloading MinGW

Access the address: https://sourceforge.net/projects/mingw-w64/ in the tab: Files and in MinGW-W64 GCC-8.1.0 (if you have a later version, choose her) and download the file:
x86_64-posix-seh and after downloaded: unzip the file:

gcc/g++ MinGW Windows 1

2. Installation

Move the unzipped folder to the C:\ drive and copy the address of the bin subfolder the full path is: C:\mingw64\bin

3. Create Environment Variables

Search the Startbar for the word Environment Variables , click on the first option and then on the button: Environment Variables, a new window will open:

In the bottom box (System Variables), select Path and click on the Edit button, in the window that opened click on the New button and paste the path address: C:\mingw64\bin:

gcc/g++ MinGW Windows 6

4. Testing in PowerShell and cmd

Open PowerShell or CMD, enter the folder where there is a C/C++ file, compile and run:

gcc/g++ MinGW Windows 7

gcc/g++ MinGW Windows 8

In VS Code it is easier to use:

VS Code

To facilitate the opening of PowerShell in VS Code you can install this extension.


If you wish, you can choose to follow this tutorial to install with MSYS2, however I find it messier, MSYS2 creates a bunch of shortcuts.


See too:

Create Games for Windows, Linux and Web with Raylib C/C++


windows

gcc

cpp

clanguage



Related articles



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.

Last Updated :
06 Feb, 2023

MinGW is a native C/C++ compiler(GCC) which have free distributable import libraries and header files for building native Windows applications. In this tutorial, we are going to install MinGW for C/C++. These are a few steps that we have to perform to successfully install MinGW on our device. 

How to Install the MinGW Tools for C/C++?

Step 1: Go to the MinGW website and click on Download. It will start downloading in 5 seconds.

Step 2: Double click and open the exe MinGW file and click install. It will automatically start downloading all the setups for the MinGW. 
Step 3: After all of the setup click Continue. Now the MinGW installation manager will pop up.

Step 4: In the installation manager right click on every option and then click Mark for Installation

Step 5: In the Installation, option-click Apply changes. And then select Apply. It will start downloading all the files. It will take 5-6 minutes. After finishing click on Close. 

How to Change Environment Variables for MinGW

After successful installation of MinGW, next step is to change the environment location for MinGW.

Step 1:  Go to the C drive on your device and search for the MinGW folder. And in the MinGW folder go to the bin folder and copy its path.

Step 2: Go to the control panel then go to System then Advanced system settings and then Environment variables. 

Step 3: In the system variables search for path and then select Edit. Now add a new path to it by clicking New. Now paste the path and click ok. 

This marks the complete installation of MinGW in the system.

Another method to change Environment Variable for MinGw.

Step 1:  Go to the C drive on your device and search for the MinGW folder. And in the MinGW folder go to the bin folder and copy its path.

Step 2: Now go to this pc and right click there and click on show more properties and click on properties pointed by the arrow.

Step 3: Now click on Advanced system setting.

Step 4: Now click on environmental variables.

Step 5: Now in system variables click on path and click on edit button.

Step 6: Now click on new button and paste the copied path there as shown in photo.

Now click on “ok” button of step 6, 5 and 4. and then close all the windows and restart your pc.

This marks the complete installation of MinGW in the system.

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

  • GNU
  • GCC
  • MinGW
  • Install MinGW on Windows
    • Check if MinGW has been Installed Successfully
    • Compile and run your first C program through Command Prompt
  • Conclusion
  • FAQ’s
    • What is MinGW and why do I need it for C programming on Windows?
    • What is the purpose of the GCC compiler in MinGW?
    • How can I check if MinGW has been installed correctly?
    • Is MinGW a compiler or an IDE?
    • How do I compile and run my first C program using MinGW in the Command Prompt?

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.

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.

MinGW components

MinGW Components Illustration

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

Install MinGW on Windows: Step 1

When the download is complete, click the .exe file. Then click on Install.

Install MinGW on Windows: Step 2

Install MinGW on Windows: Step 2

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

Install MinGW on Windows: Step 3

When the MinGW installation is complete, click on Continue.

Install MinGW on Windows: Step 4

Install MinGW on Windows: Step 4

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

Install MinGW on Windows: Step 5

Click on Apply.

Install MinGW on Windows: Step 6

Install MinGW on Windows: Step 6

When the MinGW installation is complete, click on Close.

Install MinGW on Windows: Step 7

Install MinGW on Windows: Step 7

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

Install MinGW on Windows: Step 8

Click on the environment variables.

Install MinGW on Windows: Step 9

Install MinGW on Windows: Step 9

From the system, variables click on the Path and select Edit.

Install MinGW on Windows: Step 10

Install MinGW on Windows: Step 10

Click on New to add a new path.

Install MinGW on Windows: Step 11

Install MinGW on Windows: Step 11

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

Install MinGW on Windows: Step 12

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.

Check a successful installation of MinGW

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:

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.

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.

Compile and execute a C program MinGW

Compile and execute a C program

If you want to create an executable file directly you can use the following command:

If you don’t specify any name for the executable file, by default its name will be a.

Execute a C program

Conclusion

Installing MinGW on Windows is a simple process that requires following our step-by-step guide with screenshots. With MinGW set up, you can easily compile, and execute your C/C++ code directly through the command prompt. It’s a straightforward way to start coding in C on your Windows machine.

If you still haven’t explored C language much, start your journey by learning the history, features, and uses of C.

FAQ’s

What is MinGW and why do I need it for C programming on Windows?

MinGW is a minimalist development environment for Windows that provides the GCC compiler to compile and run C programs directly on a Windows machine.

What is the purpose of the GCC compiler in MinGW?

GCC is the GNU Compiler Collection, a tool provided by MinGW to compile C programs. It converts your C code into executable machine code that can run on your Windows system.

How can I check if MinGW has been installed correctly?

You can verify the installation by opening the Command Prompt and typing gcc --version. If MinGW is installed properly, it will display the installed version of GCC.

Is MinGW a compiler or an IDE?

MinGW is not an IDE; it’s a development environment that includes the GCC compiler and other tools needed to build C programs. You can use it with a code editor or IDE to compile and run your code.

How do I compile and run my first C program using MinGW in the Command Prompt?

After installing MinGW, write your C program in a .c file. Open the Command Prompt, navigate to the file’s location, and type gcc filename.c -o outputname to compile. Then, run the program by typing outputname to see the results.

MinGW-w64 (Minimalist GNU for Windows) is a popular software development environment for compiling native Windows applications. It offers a complete open-source programming environment that includes libraries and compilers. Unlike the original MinGW, MinGW-w64 supports both 32-bit and 64-bit Windows binaries and is more actively maintained. This guide will walk you through the process of installing MinGW-w64 on Windows 11, helping you set up a robust development environment to work on your projects.

Understanding the Prerequisites

Before diving into the installation process, it is vital to understand the prerequisites for successfully installing MinGW-w64. First, ensure that your Windows 11 operating system is fully updated, as this can solve potential compatibility issues during installation.

Next, you will need administrative rights on your computer. This permission allows the installation process to create directories and add environment variables without any hindrances. If you are unsure whether you have administrative rights, please check with your system administrator or proceed with the installation and grant permissions when prompted.

Downloading MinGW-w64

The first step in the installation process is to download MinGW-w64 from the official source. Follow these instructions to obtain the latest version:

  1. Visit the official MinGW-w64 website:
    Open your web browser and navigate to the MinGW-w64 GitHub repository or the official MinGW-w64 download page on SourceForge.

    • GitHub URL: MinGW-w64 GitHub Releases
    • SourceForge URL: MinGW-w64 on SourceForge
  2. Locate the Installer:
    On the download page, you’ll find several files listed. For most users, the «mingw-w64-install.exe» or the latest installer file is the most straightforward option as it will guide you through the installation process.

  3. Download the Installer:
    Click on the desired installer link, and the download should begin automatically. The file size may vary; make sure to check your internet connection stability during the download.

Running the Installer

Once the download is complete, we can proceed with the installation. Follow these steps to run the installer successfully:

  1. Locate the downloaded file:
    Go to your Downloads folder or the location where you saved the installer file.

  2. Run the installer:
    Double-click the «mingw-w64-install.exe» file. If prompted by the User Account Control (UAC), click «Yes» to allow the installer to make changes to your system.

  3. Choose the installation settings:

    • Architecture: You will be presented with the choice of the architecture to install. Choose between x86_64 for 64-bit systems or i686 for 32-bit systems. For Windows 11, it is recommended to select x86_64.
    • Threads: Choose the threading model; posix is generally preferable for compatibility with POSIX-compliant systems.
    • Exception: Choose seh (Structured Exception Handling) for the architecture you selected, as it adds better support for debugging and exception handling.
  4. Select the installation directory:
    Next, you will be asked to choose the installation directory. You can use the default location or create a new directory (e.g. C:mingw-w64). If you create a custom directory, remember to avoid spaces in the directory name as it may lead to complications later.

  5. Install:
    Click the “Next” button, review your selections, and then click “Install” to begin the installation process. The installation may take a while, depending on your system specifications.

Once the installation process is complete, you will see a confirmation message. Click “Finish” to close the installer.

Adding MinGW-w64 to the System Path

To ensure that MinGW-w64 can be called from any command prompt window, you need to add it to the system PATH. This step allows you to invoke the gcc (GNU Compiler Collection) compiler from any directory in the command prompt.

  1. Open the System Properties:
    Right-click on the «Start» button or press Windows + X and select «System.» In the System window, click on «Advanced system settings» on the left sidebar.

  2. Environment Variables:
    In the System Properties window, click on the «Environment Variables» button at the bottom.

  3. Edit the PATH Variable:
    Under the «System variables» section, scroll down and find the «Path» variable. Select it and click on «Edit.»

  4. Add a New Path:
    In the Edit Environment Variable window, click «New» and add the path to the bin directory of your MinGW-w64 installation. For example:

    C:mingw-w64mingw64bin

    Adjust this path according to your installation directory.

  5. Confirm Changes:
    Click «OK» to close the Edit Environment Variable window, and then click «OK» again to close the Environment Variables window. Finally, click «OK» in the System Properties window.

Verifying the Installation

To verify that MinGW-w64 is installed correctly and available in your PATH, you can perform the following steps:

  1. Open Command Prompt:
    Press Windows + R, type cmd, and hit Enter to open the Command Prompt.

  2. Check GCC Version:
    In the Command Prompt window, type the following command and press Enter:

    gcc --version

    If MinGW-w64 is installed correctly, you should see output that includes the version of GCC and details about the compiler.

  3. Test Compilation:
    Create a simple «Hello, World!» C program to test the compilation process. Use Notepad or any text editor to create a file called hello.c with the following code:

    #include 
    
    int main() {
       printf("Hello, World!n");
       return 0;
    }

    Save the file in a directory of your choice. Use the command prompt to navigate to that directory by typing cd followed by the path to your directory. Then, compile the program using:

    gcc hello.c -o hello.exe

    After compiling, run the executable with:

    hello.exe

    If you see the message «Hello, World!» printed in the console, congratulations! You’ve successfully installed and tested MinGW-w64.

Configuring Code Editor or IDE

To improve your development experience, it is advisable to utilize a code editor or Integrated Development Environment (IDE) that complements MinGW-w64. Some popular choices include:

  • Visual Studio Code (VS Code): A lightweight and versatile code editor that offers extensive features through extensions. You can install extensions for C/C++ to improve your coding experience.
  • Code::Blocks: A free C/C++ IDE that is easy to set up and use with MinGW-w64.
  • Eclipse CDT: A powerful IDE that supports C/C++ development. You’ll need to configure it to work with MinGW-w64.

To configure these programs, you typically need to specify the path to the MinGW-w64 installation in the settings. This process varies from one editor to another, so referring to the editor’s documentation is essential for proper configuration.

Setting Up Additional Tools

Once you’ve established a functional installation of MinGW-w64, consider integrating additional tools or libraries to enhance your development capabilities:

  1. CMake: If you’re dealing with larger projects or libraries, using CMake can streamline your build process. Download and install CMake from its official website.

  2. Git: For version control and managing your code repositories, Git is essential. Install it from the official Git website.

  3. Debugger: Familiarize yourself with debugging tools. GDB is integrated into MinGW-w64, but you may also explore debugging plugins for your code editor.

  4. Text Editors/IDEs Extensions: Depending on your coding needs, you might want to explore various extensions that help in debugging, porting, and enhancing the coding environment.

  5. Libraries: Look into libraries you might want to use within your applications. Popular libraries like SDL, SFML, or OpenGL can often be compiled with MinGW-w64.

Conclusion

Installing MinGW-w64 on Windows 11 is a straightforward process that unleashes powerful development capabilities on your system. By following these steps, you’ve learned how to download, install, and configure MinGW-w64. Along with a well-chosen IDE or code editor, you’ll have a powerful environment to bring your software projects to life.

Whether you’re working on small projects or embarking on larger software development tasks, MinGW-w64 provides the tools necessary for success. With your new setup in place, you can dive into the world of C and C++ programming confidently, backed by the full power of the GNU Compiler Collection on Windows 11. Happy coding!

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Windows xp home edition 2001
  • Counter strike windows 10 torrent
  • Автовыключение монитора windows 10 как отключить
  • Внешний вид mac os на windows
  • Драйвер xmos для windows 10