0
0
CHow-ToBeginner · 4 min read

How to Install C Compiler on Windows: Step-by-Step Guide

To install a C compiler on Windows, download and install MinGW or TDM-GCC, which provide the gcc compiler. After installation, add the compiler's bin folder to your system PATH environment variable to use it from the command line.
📐

Syntax

After installing a C compiler like MinGW, you use the gcc command in the Windows Command Prompt to compile C programs.

  • gcc filename.c -o outputname: Compiles filename.c into an executable named outputname.exe.
  • gcc filename.c: Compiles and creates a.exe by default.
bash
gcc hello.c -o hello.exe
💻

Example

This example shows a simple C program and how to compile and run it using the installed compiler.

c
#include <stdio.h>

int main() {
    printf("Hello, Windows C Compiler!\n");
    return 0;
}
Output
Hello, Windows C Compiler!
⚠️

Common Pitfalls

  • Not adding the compiler's bin folder to the PATH environment variable causes the gcc command to be unrecognized.
  • Installing incomplete or outdated versions of MinGW can cause missing libraries or errors.
  • Running commands in PowerShell without proper syntax may cause issues; use Command Prompt or adjust commands accordingly.
none
REM Wrong: gcc command not found if PATH not set

REM Right: Add C:\MinGW\bin to PATH environment variable
📊

Quick Reference

Summary tips for installing and using a C compiler on Windows:

StepDescription
Download MinGW or TDM-GCCGet the installer from official sites
Run installerSelect C compiler and install to a folder like C:\MinGW
Add bin folder to PATHInclude C:\MinGW\bin in system environment variables
Open Command PromptUse cmd.exe to run gcc commands
Compile C codeUse gcc filename.c -o outputname.exe to build executables

Key Takeaways

Download and install MinGW or TDM-GCC to get a C compiler on Windows.
Add the compiler's bin folder to your system PATH to run gcc from the command line.
Use the gcc command to compile C programs into executables.
Always run commands in Command Prompt or configure PowerShell correctly.
Check your installation if gcc is not recognized or libraries are missing.