MinGW-w64 installation detailed steps (c/c++ compiler gcc, g++ windows version, win10, win11 are available)

Article directory

  • 1. Definition of MinGW
  • 2. The main components of MinGW
  • 3. Download and install MinGW-w64
      • 3.1. Download, decompress and install the address
      • 3.2, MinGW-w64 environment variable setting
  • 4. Verify that MinGW is installed successfully
  • 5. Write a simple code verification
  • 6. Summary

1. Definition of MinGW

MinGW (Minimalist GNU for Windows) is a development toolset for the Windows platform, which provides a set of GNU tools and libraries that can Used to compile and build native Windows applications. The goal of MinGW is to provide development tools similar to Unix/Linux in the Windows environment, so that developers can easily Write and compile C, C++, etc. programs on >Windows.

2. The main components of MinGW

  • GCC (GNU Compiler Collection): GCC is an open source compiler suite that supports multiple programming languages, including C, C++, Fortran etc. In MinGW, GCC is used to compile and generate executables for the Windows platform.

  • Binutils: Binutils is a set of tools for working with binary files, including assemblers, linkers, object file processors, and more. In MinGW, Binutils is used to convert compiled source code into an executable.

  • Runtime Libraries: MinGW provides C and C required under Windows + + Runtime libraries, which are required at compile and link time to run programs in the Windows environment.

  • MSYS (Minimal SYStem): MSYS is a lightweight Unix-like environment on Windows Some basic Unix command-line tools are provided, so that developers can use the command line for development and construction more conveniently.

MinGW can be used with other development toolsets such as Visual Studio, but its focus is to provide an easy way to Develop without relying on a complex integrated development environment (IDE). The use of MinGW allows developers to get closer to the standard development environment, and also facilitates cross-platform development.

It should be noted that MinGW and MSYS2 are two different projects, and while their names and goals are similar, there are some differences. MSYS2 provides a more advanced package management system and some additional tools based on MinGW, making development on Windows easier.

3, MinGW-w64 download and installation

3.1, download, decompress and install URL

  • Official download site:MinGW-w64 – for 32 and 64 bit Windows download | SourceForge.net.

  • Find the latest version at the bottom of this page:

  • x86_64 refers to the 64 operating system, and i686 refers to the 32 operating system. Now the system is a 64 operating system, so choose x86_64.

  • win32 is a protocol for developing windows system programs, and posix is a protocol for other systems (such as Linux, Unix, Mac OS).

  • Exception handling model seh (new, 64-bit only), sjlj (stable, both 64-bit and 32-bit), dwarf (Better than sjlj, only supports 32-bit systems)

  • Click the link and wait for 5 seconds to download.

  • Then just unzip:
  • The decompression is almost like this:
  • Then you can find g++.exe or gcc.exe in the bin directory:

3.2, MinGW-w64 environment variable setting

  • Click on Properties for this PC:
  • Click Advanced System Settings:
  • Click on Environment Variables:
  • Click to create a new environment variable in the system variable. The name of the environment variable is MinGW_HOME here, and the value is the path of your installation:

  • Then click the PATH environment variable in the system variables to create a new environment variable. The path is the path of the bin directory under the installation directory, because both gcc.exe and g++.exe are in it:

  • Or you can also set the path like this:

4. Verify that MinGW is installed successfully

  • windows + r to open the command line manager and enter cmd:
  • Then enter gcc -v or g + + -v or gcc –version or g + + –version:

5. Write a simple code to verify

– Create a new main.cpp in this directory or in any directory:

  • code show as below:
#include<iostream>
#include <stdio.h>
int main(){<!-- -->
std::cout<<"mingw"<<std::endl;
printf("mingw\\
");
return 0;
}
  • In this path, enter cmd to enter the command line mode:
  • Input g ++ mainin.cpp will generate a.exe:
  • Direct a.exe, the result will be output:

6. Summary

gcc or g++ is a compiler for c/c++, but it is usually only available on Linux. If we want to use it on windows, we need to use it with the help of MinGW.

MinGW (Minimalist GNU for Windows) is a development tool set, mainly used in Windows environment to use GNU tools similar to Unix/Linux environment, including gcc (GNU Compiler Collection) and g++ (GNU C + + Compiler) and other compilers.

MinGW provides a way to do C and C++ programming on Windows, enabling developers to use common compilers, linkers and tools to compile source code into executable files, just like in Same in Unix/Linux environment. Through MinGW, developers can use standard C/C++ compilers, and can also access some commonly used command-line tools to achieve cross-platform development on Windows.

One of the goals of MinGW is to provide a lightweight development environment that enables developers to write and compile native C/C++ programs on Windows without relying on a large integrated development environment (IDE). Developers can use gcc and g++ commands to compile and link programs on the command line, and can also develop with other text editors.

In short, MinGW is a way to use GNU tools such as gcc and g++ on the Windows platform, and is suitable for developers who want to do C and C++ development on Windows.