Oct 27, 2023 10 min read

Install C/GCC Compiler for Windows

Install C/GCC Compiler for Windows with our step-by-step tutorial. Compilers convert source code into machine-readable format.

Install C/GCC Compiler for Windows
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about installing C/GCC Compiler for Windows, let's briefly understand – What is compilers?

Compilers are used to convert source code into machine-readable code that the computer can comprehend. We must setup a compiler for each programming language.

There are two methods to set up a compiler in C. The first is to manually install the C/GCC compiler, and the second is to manually load Code:: Blocks or any IDE (Integrated Development Environment), which during installation also includes the GCC compiler.

Since the compiler enables the C program to be built from any directory on your computer, we must assign its path to environment path variables after installing the compiler.

In this tutorial, you will install C/GCC Compiler for Windows. We will also address a few FAQs on Download and Install C/GCC Compiler for Windows.

Scope

  • The tut0rial walks you through the installation of the C/GCC compiler for Windows.  
  • The tutorial provides information on the various kinds of source code editors used by the developers and the download link.

Source Code Editors

A text editor tool called a source code editor was created specifically to edit or write source code for any programming language. Windows comes with a basic source code editor called Notepad, but it has few features. As a result, you should use another editor if you want improved formatting and features like multiple tabs and plugins.

  1. TextPad (only for Windows) is a strong general-purpose editor for plain text files. We can simply type the C programme in TextPad. You can access Project folders within the textpad to avoid having to open files again and again, like in notepad.
  2. Notepad++ (only for Windows): A text editor for Microsoft Windows. Multiple windows are supported, unlike notepad.
  3. V.S. Code (for Windows, Mac, and Linux) You receive word completion recommendations from Visual Studio Code. A built-in debugger allows you to track each line of code.
  4. ATOM: (for Windows, Mac, and Linux): Atom's smart and flexible autocomplete helps you write code quicker.
  5. Sublime Text: Sublime Text is a free source code editor that can be expanded with extensions. It is community-built, covers almost all programming languages, and is maintained under a free licence.

Installing C/GCC Compiler for Windows

C/GCC Compiler

The steps to download and installed the MinGW GCC Compiler for Windows are listed below.

Step 1: Search the Web for MinGW C Compiler.

Search for MinGW C Compiler in your preferred browser or click the sourceforge.net link to obtain the MinGW compiler.

Step 2: Download MinGW.

The MinGW setup file will begin downloading once you select the website's green download button.

Step 3: Find the MinGW-get-setup.exe file and begin the installation process.

Double-click the setup.exe file you found in your Downloads folder.

Double-clicking the setup file will cause the MinGW Installation Manager Setup tool to launch. It will display details such as the name, version, etc. The download will begin once you click the Install button.

Step 4: Specify Installation Preferences.

You will now be prompted by the installation manager to enter your installation settings. You will be prompted to select the installation directory for that. If you want to change it, you can use the explorer to browse and specify the location as per your requirement. Click Continue to move forward after that.

Installing it in the default location is advised.

Step 5: Download and Install MinGW Installation Manager.

The necessary files for installing MinGW on your Windows system will now be downloaded immediately by the installer. Grab a coffee and wait calmly for the installation manager to complete downloading all the files. When it is finished, select continue to move forward.

It should be noted that active internet access is needed throughout the installation process.

Step 6: Choose Packages Required for the Compiler.

For the fundamental MinGW configuration, you must select one of three packages from the MinGW Installation Manager.

1. MinGW32-base Package

Installing the MinGW32-base package is the first step. The linker and other binary tools included in this package are used to compile the C program. Right-click the MinGW32-base option and click Mark for Installation.

2. MinGW32-gcc-g++ Package.

Installing the MinGW32-gcc-g++ package is the next step. C++ source code is compiled using this package. The MinGW Compiler includes this as an optional component. It is only necessary if you intend to only use the C++ programming language. Right-click on the MinGW32-gcc-g++ file to select it, then choose Mark for Installation.

3. MinGW32-gcc-objc package.

Installing the MinGW32-gcc-objc package is the last step. The objective C language is compiled using this package. It is an optional element. It is only necessary if you plan to programme in Objective C. Right-click the MinGW32-gcc-objc package and choose Mark for Installation.

Step 7: Apply the Changes

Go to Installation>>Apply Changes and click on Apply Changes after choosing all the necessary packages.

Step 8: Download the Changes.

It's time to start downloading every one of the packages you choose in the previous step. Click Apply and continue to download and install them.

As seen in the window below, the packages' download will now start. Wait until the download is finished, which should take a few minutes.

Step 9: Installation Completed.

Clicking on Close will close the Installation Manager now that the installation is complete.

The installation of MinGW is now complete. Launch Command Prompt and enter the command g++ --version to see if it has been installed or not.

Because the environment path variable has not been configured, the MinGW compiler (GCC) cannot now be found by the command prompt. The environment path variable helps in system-wide compiler detection.

Setting up Path Variable

The steps listed below should be followed to configure the Windows C compiler's path:

Step 1: Copy the MinGW bin's path.

A folder named MinGW is created in C: Drive when you install the MinGW. We require the path to MinGW's bin directory in order to set the compiler's path. To begin,

  • Go to C:C:>MinGW>bin.
  • Click on the address bar in the bin folder and then copy the address.
  • We require that the environment variable's path be set to this address.
  • You can go to the location where MinGW was installed if your install location was somewhere else.

Note: The g++ --version command will function perfectly if you open the command prompt in the bin directory, however the command should work on all the directories in the computer. The environment path variable should be set primarily for this reason.

Step 2: Open Edit System Variables.

Open Edit System Variables in step two. Enter Edit the system environment variables in the search field and then click Open to continue editing system environment variables.

Step 3: Edit the Path

Choose the path and press the Edit button in the User variables for the User section.

Step 4: Setup a New Path.

  • The Edit environment variable window will popup once you click the Edit button. We can add the path using this window based on our requirements.
  • We can add the path using this window based on our requirements. Click the New button because we want to add a new path. The Edit environment variable window will now open. We can add the path using this window based on our requirements. If we want to add a new path, click the "New" button.

Step 5: Paste the Path

Click on Ok after pasting the MinGW bin's path that was previously copied.

Creating and Running a C program

Step 1: Hello World in C

Create a text file in any directory of your choice to run a C program.

Step 2: Type the C code and Save the file

In notepad, enter the code, and then save the document with the .c extension. To show this step, we develop a programme that prints hello world and save it as Hello.c.

Step 3: Open Command Prompt

Now type cmd into the address bar in the directory of the C program and hit Enter.

Step 4: Compile the C program

Enter gcc Hello.c (or the name you'll give the program when you save it) to compile the Hello World code we created previously. The Windows C compiler will be launched when you type gcc.

Step 5: Compilation completed

The compiled file will be named a and saved in the same directory (the name can be different for you). The file will be of the Application type.

Step 6: Running the C Program

Write the compiled file's name, a, as shown in the screenshot below, to run the compiled file. Finally, the output will be displayed on the command prompt.

There are several ways to install C Compilers. Installing Code::Blocks IDE is one of them.

Let's walk through the process of installing Code::Blocks IDE with C Compiler step by step.

Alternate Method:

Installation using CodeBlocks IDE Binary release

Code::Blocks Code::Blocks is a C/C++ IDE. It includes plugins, which are optional, external additions to any software that allow for customization. By installing a plugin, any functionality can be increased. Plugins such as a debugger, text formatter, and so on can be added to the IDE.

To download and install the Code::Blocks IDE, follow the instructions below.

Step 1: Go to Code::Blocks Website

Installing the Code blocks IDE is the initial step. Launch codeblocks.org in any of the available browsers. The web page shown below will appear on your screen. Choose Downloads from the menu on the left.

Step 2: Choose the way to download

The next page will load after you click on the downloads on the downloads page. Click on the

As we will be using the binary release for this tutorial, download the binary release.

Step 3: Choose the version for download

Click on the codeblocks-20.03mingw-setup.exe (for the 64-bit version) in the Windows section.

The MinGW, which includes the GCC/G++/GFortan compiler and the GDB debugger, is included with the codeblocks-20.03mingw-setup.exe.

Using the codeblocks-20.03mingw-32bit-setup.exe will allow you to get the 32-bit version.

As shown in the screenshot below, you can download the file by clicking the link that appears before the selected version.

Step 4: Start the installation

The installation file has now been downloaded. The setup window will display on the screen when you double-click the file. To continue, select the Next> button.

Step 5: Accept the License Agreement

The terms and conditions licence agreement will show up on the screen. After reading the licencing agreement, selecting the I Agree button will allow you to continue.

Step 6: Choose Components

Check whether or not each checkbox is checked in this stage. All of the components should be chosen to provide a seamless installation. Click on Next to proceed after that.

Step 7: Choose the install location and start installing

Choose the drive location where the application will be installed. It defaults to C: Drive as the location. Click on browse and choose the location, and click on Next to continue to change it.

As soon as the installer has finished extracting the files to the destination folder you specified in the previous step, the installation process will commence.

Step 8: Installation complete

The installation has been completed successfully. When the installation is complete, a notice will appear asking Do you want to run Code::Blocks now? will show up. To open the Code::Blocks IDE, simply click the Yes button.

Make sure that the IDE now detects the Windows C compiler. Follow the instructions below to accomplish that.

Step 9: Setting up MinGW to PATH.

Go to C:\Program Files\CodeBlocks\MinGw\bin in your PC to access the MinGW folder. The following folder will be opened on your PC. Simply copy the address bar's path.

Now go back and follow the instructions in the section in the previous section called Setting up PATH Variable. Having configured the Environment path variable, proceed with the next steps.

Step 10: Compiler auto-detection

The GNU GCC compiler status is displayed as Detected in the Compilers auto-detection window as soon as you launch the Code::Blocks IDE.

Creating and Running a C Program in Code::Blocks.

Step 1: Open a New File in Code::Blocks.

To see if the IDE is functioning properly, choose File>>New>>Empty File and click on it.

Step 2: Create a Hello World program in C

Create a C hello world program. Use the .c extension to save it.

Step 3: Output of C Program

The programme will build and run when you save it by selecting Build>>Run. The code blocks have been deployed successfully if the command prompt with "hello world".

FAQs on Download and Install C/GCC Compiler for Windows

What is MinGW-w64? 

MinGW-w64 is a development environment for Windows that provides a set of open-source tools and libraries, including the GCC compiler suite, to compile and run C and C++ programs on Windows.

How do I install the C/GCC compiler on Windows using MinGW-w64? 

To install the C/GCC compiler using MinGW-w64, you can follow these general steps: - Download the MinGW-w64 installer from the official website. - Run the installer and select the desired components, including the C compiler. - Specify the installation directory and complete the installation process. - Set the PATH environment variable to include the MinGW-w64 bin directory.

What is TDM-GCC? 

TDM-GCC is a distribution of the GCC compiler for Windows that includes additional libraries and tools to simplify the development process.

How can I install the C/GCC compiler using TDM-GCC? 

To install the C/GCC compiler using TDM-GCC, you can follow these general steps: - Download the TDM-GCC installer from the official website. - Run the installer and select the desired components, including the C/C++ compiler. - Choose the installation directory and complete the installation process. - Add the TDM-GCC bin directory to the PATH environment variable.

Can I use an Integrated Development Environment (IDE) with the C/GCC compiler? 

Yes, you can use various IDEs such as Code::Blocks, Dev-C++, or Visual Studio Code, which provide a more user-friendly interface and code editing features with the C/GCC compiler.

After installing the C/GCC compiler, how do I verify if it's working correctly? 

Open a command prompt or terminal, type gcc --version, and press Enter. It should display the GCC version installed and indicate that it's recognized as a valid command.

Are there any alternatives to installing the C/GCC compiler on Windows? 

Yes, you can also consider using online compilers or toolchains such as Compiler Explorer (godbolt.org), which allow you to write and compile C code directly in the browser without installing anything locally.

Conclusion

  • A C compiler for Windows is used to compile the source code so that the computer can understand it.
  • On a Windows system, the C Compiler for Windows can be installed, first by merely installing the compiler and second by installing a compiler with IDE as a plugin.
  • The C language uses the C/GCC compiler.
  • So that it can be used in any directory, we must set the compiler's path in the Environment path variable.
  • The program must be saved with the .C extension in order to use the C Compiler.

If you have any suggestions or queries, kindly leave them in the comments section.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.