sodcalculator

10 Tech How-To

Install GCC on Windows: Steps & Tools

Guide 10-49755 · Updated · Step by step

To install GCC on Windows, the most straightforward method is to use a package manager like MSYS2 or WinLibs, which provide pre-built GCC binaries. Alternatively, you can install the Windows Subsystem for Linux (WSL) and use its package manager. This guide walks you through the main options, explains what GCC is, and helps you choose the right setup for your needs.

What Is GCC and Why Do You Need It?

GCC (GNU Compiler Collection) is a free, open-source set of compilers for C, C++, Fortran, and other languages. It is the standard compiler on most Linux systems and is widely used for cross-platform development. On Windows, GCC is not included by default, so you must install it separately if you want to compile C or C++ code without relying on Microsoft’s Visual C++ compiler.

Many open-source projects and libraries assume GCC is available, and some build tools (like CMake) work more smoothly with it. If you are following tutorials written for Linux or macOS, using GCC on Windows will make the commands match more closely.

Method 1: Install GCC with MSYS2 (Recommended)

MSYS2 is a software distribution and building platform for Windows. It provides a Unix-like environment and a package manager called pacman, which makes installing and updating GCC simple.

  1. Download the MSYS2 installer from the official website (msys2.org).
  2. Run the installer and follow the default steps. It installs to C:\msys64 by default.
  3. After installation, open the “MSYS2 UCRT64” or “MSYS2 MinGW64” terminal from the Start menu.
  4. Update the package database and core packages: pacman -Syu
  5. Install GCC and essential tools: pacman -S mingw-w64-ucrt-x86_64-gcc (or the MinGW64 version if you chose that terminal).
  6. Verify the installation: gcc --version

The UCRT64 environment is the modern default and works well with most systems. If you need 32-bit support, choose the MinGW32 variant instead.

Method 2: Install GCC with WinLibs (Standalone)

WinLibs provides standalone builds of GCC for Windows, bundled with MinGW-w64. It does not require a package manager; you just download and extract the archive.

  1. Go to winlibs.com and download the latest standalone build (choose the one that matches your architecture, e.g., UCRT or MSVCRT).
  2. Extract the ZIP archive to a folder like C:\mingw64.
  3. Add the bin folder (e.g., C:\mingw64\bin) to your system PATH environment variable.
  4. Open a new Command Prompt and run gcc --version to verify.

WinLibs is a good choice if you want a simple, portable installation without a package manager. However, you must manually update GCC when new versions are released.

Method 3: Install GCC via WSL (Windows Subsystem for Linux)

WSL lets you run a full Linux distribution inside Windows. This gives you a native Linux environment with GCC pre-installed or easily installable via apt.

  1. Enable WSL by running wsl --install in an elevated PowerShell or Command Prompt.
  2. Restart your PC if prompted.
  3. Launch the installed Linux distribution (e.g., Ubuntu) from the Start menu.
  4. Update packages: sudo apt update
  5. Install GCC: sudo apt install gcc
  6. Check with gcc --version.

WSL is ideal if you are doing Linux-targeted development or need a full Unix toolchain. The downside is that it runs in a virtualized environment, so file access between Windows and Linux can be slower, and you must use Linux commands in the WSL terminal.

How to Choose the Right Method

Your choice depends on your primary use case:

  • Beginner or casual use: MSYS2 is the most reliable and easy to update. It also provides many other Unix tools.
  • Portable or offline use: WinLibs is a single folder you can carry on a USB drive.
  • Linux-focused development: WSL gives you a real Linux environment, which is best for projects that rely on Linux-specific libraries.
  • Windows-native GUI apps: You might be better off with Microsoft’s Visual Studio and its MSVC compiler, as it integrates with Windows APIs more naturally.

If you are unsure, start with MSYS2. It is the most common recommendation and has a large user base, so finding help is easy.

Common Problems and Fixes

Here are issues you may encounter and how to resolve them:

  • “gcc is not recognized as an internal or external command” — This means the bin folder is not in your PATH. Re-check the PATH variable and ensure you restarted the terminal.
  • Missing DLL errors when running compiled programs — This usually happens when using WinLibs with the MSVCRT variant. Install the Microsoft Visual C++ Redistributable, or use the UCRT build instead.
  • “Cannot find -lstdc++” or similar linker errors — This indicates that the C++ standard library is not installed. Install the gcc package which includes it, or check that your compiler is set to use C++ (e.g., g++).
  • Compiler crashes or behaves unexpectedly — Make sure you are using the correct terminal (e.g., MSYS2 UCRT64 vs. MinGW64) and that your PATH does not have conflicting compiler installations.

If you get stuck, search the error message online — it is likely someone else has solved it.

GCC vs. Other Windows Compilers

GCC is not the only compiler option on Windows. The main alternatives are:

  • Microsoft Visual C++ (MSVC) — Comes with Visual Studio. It is the standard for Windows development, has excellent debugging tools, and is free for individual use. However, it does not fully support some C99/C11 features and uses different command-line flags.
  • Clang — A compiler that is mostly compatible with GCC’s command-line syntax. It often provides better error messages and is used by many IDEs. You can install it via MSYS2 or LLVM’s official installer.
  • Intel C++ Compiler — Optimized for Intel processors, but not free for all use cases.

For most users, GCC is a solid choice because it is free, open-source, and widely used. If you are developing Windows-only applications that use the Win32 API heavily, MSVC might be more convenient.

Frequently Asked Questions

Is GCC free to use?

Yes, GCC is free and open-source software, released under the GNU General Public License. You can use it for personal, educational, or commercial projects without paying.

Do I need to install MinGW separately?

MinGW-w64 is a project that provides a Windows port of GCC. When you install MSYS2 or WinLibs, you are effectively installing MinGW-w64 along with GCC. You do not need to install them separately.

Can I use GCC with Visual Studio Code?

Yes. Install the C/C++ extension by Microsoft, then configure the compiler path to your GCC executable. You can set up tasks.json to compile and run your programs.

How do I update GCC once installed?

If you used MSYS2, run pacman -Syu to update all packages, then pacman -S mingw-w64-ucrt-x86_64-gcc to ensure the latest GCC. For WinLibs, you need to download the new version and replace the folder. With WSL, use sudo apt update && sudo apt upgrade.

Why do I get “undefined reference to `WinMain’”?

This error usually means you are trying to compile a GUI application without a main function, or you are linking a console app with the wrong subsystem. For a console program, use gcc main.c; for a Windows GUI app, you need to specify -mwindows and provide a WinMain entry point.

Is it safe to install GCC?

Yes, if you download from official sources like msys2.org or winlibs.com. Always verify the SHA-256 checksum if provided. Avoid downloading from random mirror sites.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →