How-To Install GCC on your Windows device

Here is how you can Install GCC (GNU Compiler Collection) on your Windows device

What is GCC?

GCC is a very powerful tool that can be used to compile several programming languages using one base C file.

In very simple terms, if you want to write and run your C++ source code on your Windows computer. You will need a compiler specified for C++ to run it.

Popular C++ compilers include:

  1. Microsoft Visual C++
  2. Clang
  3. Intel C++ Compiler
  4. Borland C++
  5. Turbo C++

But due to its scalability and usefulness GCC is one of the most popular compilers.

  • GCC is an open-source compiler, which means that it is freely available for anyone to use and modify. This makes it a popular choice among developers who prefer open-source software.
  • It supports a wide range of platforms, including Linux, macOS, Windows, and various other Unix-like systems. This makes it a versatile choice for developers who work on multiple platforms.
  • It supports the latest C++ standards. This means that you can write modern C++ code and be confident that it will be compiled correctly.
  • It is known for its excellent performance when compiling C++ code.
  • Lastly, it is such a popular compiler, there is a large user community that provides support and resources for developers who use it. This includes documentation, forums, and online communities where developers can ask questions and get help with their code.

Overall, GCC is a reliable and widely-used compiler that has proven itself as a valuable tool for C++ developers.

In complex terms: it is a command-line tool that translates source code written in a particular language into executable binary files that can be run on a computer. GCC (GNU Compiler Collection) is a popular open-source compiler for several programming languages including C++, C, Objective-C, Fortran, Ada, and others.

Now how to download it?

The process is slightly complex compared to other compiler installations. But since it is a one-time hassle, it is advisable to install it accordingly.

  1. The first step is to download it fromĀ MinGW SourceForge page
  2. Now, run the installation manager and select the “Basic Setup” option.
  3. In the “Basic Setup” dialog, select the components you want to install, including the GCC C++ compiler. Make sure to select the latest version of the GCC C++ compiler that is available.
  4. Click the “Install” button to start the installation process. The installation manager will download and install the selected components.

Once the installation is complete, add the MinGW bin directory to your system PATH environment variable. This is necessary so that you can run the GCC C++ compiler from the command line. To add the MinGW bin directory to your PATH, follow these steps:

a. Open the Windows Control Panel and navigate to System and Security > System > Advanced system settings.

b. Click the “Environment Variables” button.

c. Under “System Variables”, scroll down and find the “Path” variable, and then click the “Edit” button.

d. In the “Edit environment variable” dialog, click the “New” button and add the path to the MinGW bin directory, which is usually located at “C:\MinGW\bin”.

e. Click “OK” to close all the dialogs.

Open a command prompt window and type the following command to verify that the GCC C++ compiler is installed and configured correctly:

g++ –version

If you get this error on running this command:

Here are a few things you can try:

  1. Check the spelling and case of the “g++” command: Make sure that you’re typing the command correctly and that you’re using lowercase letters for “g++”.
  2. Check the MinGW bin directory: Double-check that the MinGW bin directory is located at the path you added to your system PATH environment variable. If the directory is located somewhere else, you’ll need to update your system PATH accordingly. This path differs for all, hence is the main reason why users get the above error. Find the correct path and then edit it in your environmental variables.

This is the path you have to type in, first go to your C drive and click on the mysys64folder:

Once inside click on this: ucrt64 folder

Next, go to the bin:

And now copy this path:

Now edit the path accordingly:

  1. Restart your command prompt: After adding the MinGW bin directory to your system PATH environment variable, you need to restart any open command prompt windows for the changes to take effect. Make sure to close any existing command prompt windows and open a new one.
  2. Reinstall MinGW: If none of the above steps work, you might need to reinstall MinGW to make sure that the “g++” command is installed correctly.

Now you can run your C++ files by using any IDE of your choice. If we take VS code as an example. Users will be required to download the C/C++ extension for VS code.

Once done with the installation, you can now open any C file and run it accordingly: