🟢 Foundation  ·  Lesson 03

C++ Setup: GCC, MinGW, VS Code and Online Compiler

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.

C++ चलाने के लिए क्या चाहिए

C++ लिखने और चलाने को आपको दो चीज़ें चाहिए: एक compiler (जो आपके code को चलने योग्य program में बदलता है) और code लिखने की जगह (text editor या IDE)। सबसे व्यापक रूप से इस्तेमाल होने वाला मुफ़्त compiler g++ है, GCC toolset का हिस्सा।

आपके पास तीन व्यावहारिक रास्ते हैं, सबसे आसान से सबसे पूर्ण तक: online compiler, editor के साथ local compiler, या पूरा IDE। हम हर एक को कवर करेंगे।

सबसे तेज़ शुरुआत: online compiler

अगर आप बस आज सीखना शुरू करना चाहते हैं, online C++ compiler को कुछ install करने की ज़रूरत नहीं। आप browser में code टाइप करते हैं, Run दबाते हैं, और output देखते हैं। यह इस course के शुरुआती lessons के लिए आदर्श है। जब आपके programs बढ़ें, नीचे दिए local setup पर जाएँ।

Windows: MinGW (GCC)

Windows में built-in C++ compiler नहीं है, तो आप MinGW install करते हैं, जो g++ देता है।

  1. MinGW (या उसका MSYS2 version) download और install करें।
  2. Install के दौरान C++ compiler component शामिल करें।
  3. इसके bin folder को अपने system PATH में जोड़ें ताकि g++ किसी भी terminal में काम करे।
  4. नया Command Prompt खोलें और g++ --version टाइप करके जाँचें कि यह काम करता है।
💡 PATH जाँचें

अगर g++ "not recognised" है, तो PATH कदम छूट गया। MinGW bin folder को PATH में जोड़ें और terminal दोबारा खोलें।

Linux और macOS: GCC

अधिकांश Linux systems पर compiler एक command दूर है:

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

macOS पर, xcode-select --install से Xcode Command Line Tools install करना आपको C++ compiler (clang, जो वही commands समझता है) देता है।

VS Code इस्तेमाल करना

VS Code एक मुफ़्त, हल्का editor है। g++ जैसे compiler के साथ मिलकर, यह आरामदायक setup है:

  1. VS Code और आधिकारिक C/C++ extension install करें।
  2. पक्का करें कि g++ installed है और आपके PATH पर है (ऊपर देखें)।
  3. अपनी .cpp file खोलें और built-in terminal से compile तथा run करें।

Compile और run करना

आप जो भी setup इस्तेमाल करें, compile-और-run कदम वही हैं। इसे hello.cpp के रूप में सहेजें:

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

फिर terminal में:

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

आम setup समस्याएँ

  • "g++ is not recognised" — compiler आपके PATH पर नहीं है; उसका bin folder जोड़ें और terminal दोबारा खोलें।
  • File edit करना पर पुराना compiled program चलाना — हर बदलाव के बाद दोबारा compile करें।
  • गलत extension से सहेजना — file .cpp पर खत्म होनी चाहिए।
  • PATH बदलने के बाद terminal दोबारा खोलना भूलना, तो वह अब भी g++ नहीं ढूँढ पाता।
🏋️ अभ्यास

कोई एक setup चालू करें — शुरू करने को online ठीक है — और ऊपर दिए hello.cpp को सफलतापूर्वक compile तथा run करें। जब आप "It works!" देखें, आप पहला C++ program lesson के लिए तैयार हैं।

सारांश

  • C++ चलाने को compiler (आमतौर पर g++) और editor चाहिए।
  • Online compiler को कुछ install करने की ज़रूरत नहीं और शुरू करने को बढ़िया है।
  • Windows पर MinGW g++ देता है; Linux/macOS पर यह एक install command है।
  • VS Code और C/C++ extension आरामदायक local setup बनाते हैं।
  • g++ file.cpp -o name से compile करें, फिर program चलाएँ।

अक्सर पूछे जाने वाले प्रश्न (FAQ)

C++ programs चलाने के लिए मुझे क्या चाहिए?
आपको एक C++ compiler चाहिए, जो आपके code को computer के चलाने योग्य program में बदलता है। सबसे आम मुफ़्त compiler g++ है (GCC का हिस्सा)। code लिखने को आपको एक text editor या IDE भी चाहिए — कई लोग VS Code, Code::Blocks, या online compiler इस्तेमाल करते हैं।
Beginners के लिए सबसे अच्छा C++ compiler कौन-सा है?
GCC toolset का g++ सबसे लोकप्रिय मुफ़्त विकल्प है और Windows (MinGW के ज़रिए), Linux तथा macOS पर काम करता है। Beginners अक्सर इसे VS Code के साथ जोड़ते हैं या Code::Blocks जैसा all-in-one IDE इस्तेमाल करते हैं, जो compiler और editor साथ लाता है।
क्या मैं बिना कुछ install किए C++ चला सकता हूँ?
हाँ। Online compilers आपको बिना कुछ install किए browser में C++ लिखने-चलाने देते हैं, जो basics सीखने या छोटे programs test करने के लिए बढ़िया है। बड़े projects के लिए आप अंततः locally compiler चाहेंगे।
g++ से C++ program कैसे compile करूँ?
अपना code hello.cpp जैसी file में सहेजें, फिर g++ hello.cpp -o hello चलाकर उसे hello नामक program में compile करें। इसे Linux या macOS पर ./hello से, या Windows पर hello.exe से चलाएँ।
MinGW क्या है और Windows पर क्यों चाहिए?
MinGW एक package है जो GCC compiler (g++ सहित) को Windows पर लाता है। Windows में default रूप से C++ compiler नहीं होता, तो MinGW install करना आपको g++ command देता है जो आपके programs को command line या editor से compile करता है।
← Back to C++ Tutorial
🔗

Share this topic with a friend

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

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

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

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.