Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🟢 Foundation  ·  Lesson 03

C++ Compiler Setup (GCC, MinGW, VS Code)

In this lesson: Set up C++ on Windows with MinGW/GCC and VS Code, or code online — run your first program in minutes. In Hindi & English.

What you need to run C++

To write and run C++ you need two things: a compiler (which turns your code into a runnable program) and a place to write the code (a text editor or IDE). The most widely used free compiler is g++, part of the GCC toolset.

You have three practical routes, from easiest to most complete: an online compiler, a local compiler with an editor, or a full IDE. We will cover each.

Fastest start: an online compiler

If you just want to start learning today, an online C++ compiler needs nothing installed. You type code in the browser, press Run, and see the output. It is ideal for the early lessons in this course. When your programs grow, move to a local setup below.

Windows: MinGW (GCC)

Windows has no built-in C++ compiler, so you install MinGW, which provides g++.

  1. Download and install MinGW (or the MSYS2 version of it).
  2. During install, include the C++ compiler component.
  3. Add its bin folder to your system PATH so g++ works in any terminal.
  4. Open a new Command Prompt and type g++ --version to check it works.
💡 Check the PATH

If g++ is "not recognised," the PATH step was missed. Add the MinGW bin folder to PATH and reopen the terminal.

Linux and macOS: GCC

On most Linux systems the compiler is one command away:

Terminal (Ubuntu/Debian)
sudo apt update
sudo apt install g++

On macOS, installing Xcode Command Line Tools with xcode-select --install gives you a C++ compiler (clang, which understands the same commands).

Using VS Code

VS Code is a free, lightweight editor. Combined with a compiler like g++, it is a comfortable setup:

  1. Install VS Code and the official C/C++ extension.
  2. Make sure g++ is installed and on your PATH (see above).
  3. Open your .cpp file and use the built-in terminal to compile and run.

Compiling and running

Whatever setup you use, the compile-and-run steps are the same. Save this as hello.cpp:

hello.cpp
#include <iostream>
using namespace std;
int main() {
    cout << "It works!" << endl;
    return 0;
}

Then in the terminal:

Terminal
g++ hello.cpp -o hello    # compile
./hello                   # run (Windows: hello.exe)
Output:
It works!

Common setup problems

  • "g++ is not recognised" — the compiler is not on your PATH; add its bin folder and reopen the terminal.
  • Editing the file but running an old compiled program — recompile after every change.
  • Saving with the wrong extension — the file must end in .cpp.
  • Forgetting to reopen the terminal after changing PATH, so it still cannot find g++.
🏋️ Practice

Get any one setup working — online is fine to start — and successfully compile and run the hello.cpp above. Once you see "It works!", you are ready for the first C++ program lesson.

Summary

  • Running C++ needs a compiler (usually g++) and an editor.
  • An online compiler needs nothing installed and is great to start.
  • On Windows, MinGW provides g++; on Linux/macOS it is one install command.
  • VS Code plus the C/C++ extension makes a comfortable local setup.
  • Compile with g++ file.cpp -o name, then run the program.

Frequently Asked Questions

What do I need to run C++ programs?
You need a C++ compiler, which turns your code into a program the computer can run. The most common free compiler is g++ (part of GCC). You also need a text editor or an IDE to write the code — many people use VS Code, Code::Blocks, or an online compiler.
What is the best C++ compiler for beginners?
g++ from the GCC toolset is the most popular free choice and works on Windows (via MinGW), Linux and macOS. Beginners often pair it with VS Code or use an all-in-one IDE like Code::Blocks, which bundles the compiler and editor together.
Can I run C++ without installing anything?
Yes. Online compilers let you write and run C++ in your browser with nothing to install, which is perfect for learning the basics or testing small programs. For larger projects you will eventually want a compiler installed locally.
How do I compile a C++ program with g++?
Save your code in a file such as hello.cpp, then run g++ hello.cpp -o hello to compile it into a program named hello. Run it with ./hello on Linux or macOS, or hello.exe on Windows.
What is MinGW and why is it needed on Windows?
MinGW is a package that brings the GCC compiler (including g++) to Windows. Windows does not include a C++ compiler by default, so installing MinGW gives you the g++ command that compiles your programs from the command line or an editor.
← Back to C++ Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.
Next topicFirst C++ Program: Hello World Your progress: 3 / 81 (4%) · Lesson 4 / 81 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free