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++.
- Download and install MinGW (or the MSYS2 version of it).
- During install, include the C++ compiler component.
- Add its
binfolder to your system PATH sog++works in any terminal. - Open a new Command Prompt and type
g++ --versionto check it works.
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:
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:
- Install VS Code and the official C/C++ extension.
- Make sure g++ is installed and on your PATH (see above).
- Open your
.cppfile 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:
#include <iostream>
using namespace std;
int main() {
cout << "It works!" << endl;
return 0;
}Then in the terminal:
g++ hello.cpp -o hello # compile ./hello # run (Windows: hello.exe)
It works!
Common setup problems
- "g++ is not recognised" — the compiler is not on your PATH; add its
binfolder 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++.
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?
What is the best C++ compiler for beginners?
Can I run C++ without installing anything?
How do I compile a C++ program with g++?
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?
g++ command that compiles your programs from the command line or an editor.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++ देता है।
- MinGW (या उसका MSYS2 version) download और install करें।
- Install के दौरान C++ compiler component शामिल करें।
- इसके
binfolder को अपने system PATH में जोड़ें ताकिg++किसी भी terminal में काम करे। - नया Command Prompt खोलें और
g++ --versionटाइप करके जाँचें कि यह काम करता है।
अगर g++ "not recognised" है, तो PATH कदम छूट गया। MinGW bin folder को PATH में जोड़ें और terminal दोबारा खोलें।
Linux और macOS: GCC
अधिकांश Linux systems पर compiler एक command दूर है:
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 है:
- VS Code और आधिकारिक C/C++ extension install करें।
- पक्का करें कि g++ installed है और आपके PATH पर है (ऊपर देखें)।
- अपनी
.cppfile खोलें और built-in terminal से compile तथा run करें।
Compile और run करना
आप जो भी setup इस्तेमाल करें, compile-और-run कदम वही हैं। इसे hello.cpp के रूप में सहेजें:
#include <iostream>
using namespace std;
int main() {
cout << "It works!" << endl;
return 0;
}फिर terminal में:
g++ hello.cpp -o hello # compile ./hello # run (Windows: hello.exe)
It works!
आम setup समस्याएँ
- "g++ is not recognised" — compiler आपके PATH पर नहीं है; उसका
binfolder जोड़ें और 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 चलाएँ।