UPI Study › Courses › C++ Programming › Free lessons › Lesson 2.2 Free with a free account
Preparing Your Machine
C++ Programming · Chapter 2: Getting Started with C++Section 2.2 · lesson 9 of 84video coming soon
← What Separates C++ From C?Next lesson: Professional Habits: Readability Standards →
In this lesson
Tools and configuration for C++ development.
- Name the three tools a working setup needs
- Choose and install a compiler and an editor
- Explain PATH and repair it when it's wrong
- Build and run a stub file two ways
Transcript
Everything said in the video, section by section (1,509 words). Read along, or search it.
Opening Overview
Three Pieces Before Any C++ Runs
Before a single line of C++ can run, three pieces have to be in place. Something to write the text in, something that turns the text into a program, and a way to start the result and see what it says. This video installs all three, proves each one works, and leaves you with a folder you can build in, on Windows, macOS or Linux.
Core Concept
Installing C++ Means Installing Separate Tools
People say install C++ as if it were one application. It isn't. C++ is a language description. What you install is a set of separate tools that happen to work together. First, an editor or an IDE, where you type and save the text of the program. Second, a compiler, which turns that text into a file the machine can run. Third, a terminal, which starts the result and shows what it printed. An IDE bundles all three behind buttons. But only the compiler is genuinely essential. A plain editor and a terminal are enough to build anything here, which is why the command line is taught alongside the buttons. When a project misbehaves inside an IDE, dropping to the command line tells you whether the fault is in your code, or in the environment's settings.
Compiler Options
GCC, MSVC and Clang Compared
Three compilers account for nearly all C++ work. GCC, run as g++, is native to Linux, and available on Windows through MinGW. It's the one most teaching material assumes. MSVC, run as cl, is Microsoft's, installed with Visual Studio. It's run from a developer command prompt. Clang, run as clang++, is native to macOS. On a Mac, typing g++ usually runs Clang under that name. They differ in who makes them and what you type, not in the language. Code written to the standard builds under all three. Any release from the last three years or so handles everything here. What matters is knowing which one you installed, because it sets the default language standard.
Tool Choices
Editors Versus IDEs: Picking One
An editor is a program for writing text, with extras like coloring and completion. An IDE adds building, running, project management and a debugger, all in one window. Neither is better. VS Code is a light editor that works the same on every system. But it doesn't include a compiler. You install one separately, plus the C++ extension. Code::Blocks is an IDE with the shortest path: create a project, press build, press run. Just confirm which compiler it's pointed at. Visual Studio is a full IDE on Windows, with compiler, editor and debugger installed together. It's gigabytes, and not to be confused with VS Code. Pick one and stay with it for now. Switching tools repeatedly costs hours, and teaches nothing about the language.
Installation Steps
Installing a Toolchain on Your System
Follow only the section for your own system. On macOS, open Terminal and run xcode-select --install. That installs the command line developer tools. The full Xcode app isn't needed. On Debian or Ubuntu Linux, run sudo apt update, then sudo apt install build-essential. It's often already there. On Windows with g++, install MSYS2, then in its window, install the toolchain with the pacman command shown. Then add the toolchain's bin folder to your PATH. More on PATH in a moment. On Windows with Microsoft's compiler, run the Visual Studio installer, and tick Desktop development with C++. That tick is the step people miss.
Key Concept
How the PATH Finds Your Compiler
When you type g++ into a terminal, the system doesn't search your whole disk. It looks through a specific list of folders, in order, and runs the first match. That list is called the PATH. Here, it checks the Windows system folders first, and the compiler isn't there. Then it reaches the MSYS2 bin folder, finds it, and stops. The compiler runs. But type a name that no folder on the list holds, and the shell says the command isn't found. Windows says it isn't recognized. Nearly every report of, I installed it but the command isn't found, comes down to one line: the compiler's folder isn't on the list.
Verification
Proving the Install With a Version Banner
To prove the install worked, open a terminal and ask the compiler to identify itself, with dash dash version. You'll see a version banner. On a Mac, Clang answers, even when you type g++. Your exact numbers will differ, and that's fine. Any banner at all means the compiler is installed, and on the PATH. An error means one of those isn't true. One exception. If cl isn't recognized on Windows, you're almost certainly in an ordinary prompt. Open the Developer Command Prompt from the Start menu. That's not a PATH fault. Microsoft's compiler needs several settings at once, and that prompt applies them all.
Common Mistake
Editing PATH Needs a Fresh Terminal
To add a folder to PATH on Windows, search for environment variables, select Path under your user variables, choose Edit, then New, and paste the folder. On macOS and Linux, add an export PATH line to your shell's start-up file, such as dot zshrc, putting the new folder in front. And here's the mistake everyone makes. A terminal reads PATH once, at the moment it opens. A window that was open while you edited PATH is still using the old list, so your change seems to have done nothing. Close it, and open a fresh one, before deciding the edit failed. This one misunderstanding accounts for a remarkable share of lost evenings.
Quick Check
Why g++ Is Still Not Found
Quick check. You added C:\msys64 to PATH and opened a brand-new terminal, but g++ is still not found. The compiler sits in C:\msys64\ucrt64\bin. Why? Pause and think. PATH lists exact folders, and doesn't search inside them. Add the folder that directly holds g++, the ucrt64 bin folder, then open another new terminal.
Setup Advice
Choosing a Safe Working Folder
Before compiling anything, decide where files will live. One working folder, with a subfolder for each piece of work, like 01-setup, holding setup.cpp. Keep the path short, with no spaces or accented characters. Some tools handle them badly, and the errors are baffling. And keep your work out of any folder that syncs to cloud storage while you build. A sync copying files mid-build produces failures that look like compiler faults. A project in an IDE is really just a folder, plus a settings file recording how to build. In VS Code, you open a folder, and the folder is the project.
Test File
Writing the Stub Program
To verify everything, compile a stub: a deliberately tiny file whose only job is to prove the machinery works. It includes iostream, and its main function prints, Toolchain is working, and returns zero. For now, it's a test signal, not a lesson. Type it rather than pasting it. Typing exposes the two mistakes everyone makes once, a missing semicolon and a missing brace, while they're cheap. Save it with a dot cpp ending, and check your editor hasn't saved it as setup dot cpp dot txt.
Command Line
Building and Running in Two Steps
The command line route has exactly two steps, and keeping them apart is the point. The first turns your text into a program. The second starts it. Change into the folder, build with g++ and the flags shown, then run the result with dot slash setup. If the build prints nothing at all, it succeeded. Most software congratulates you. Compilers don't. No news genuinely is good news. -std=c++17 states which version of the language your file is written against. Without it, each compiler uses its own default. -Wall turns on the common warnings: leave it on permanently. -o names the output, which is otherwise a.out, or a.exe. And the dot slash matters. On macOS and Linux, the current folder isn't on the PATH, so dot slash means: the one right here. Build and run from your IDE too, and you should get the same line. When something goes wrong, knowing which step failed already halves the problem.
Troubleshooting
Reading Common Setup Error Messages
Setup failures are mostly a small, repeating set. Read the message, rather than skimming it. Command not found, or not recognized, means no folder on the PATH held the compiler. Confirm the install, add the folder, and open a new terminal. No such file or directory, for your source file, means the compiler was found, but your terminal is in a different folder from the file. If iostream itself can't be found, the compiler is there, but its library files are missing. Reinstall the whole toolchain package. An undefined reference to main, or undefined symbols, means nothing in the file is the starting point. Check the spelling of main. Permission denied usually means a copy of the program is still running. And a window that opens and closes instantly isn't a fault: the program finished. Run it from your own terminal.
Key Takeaways
A Working Setup Summarized
To summarize. A working setup is three tools: an editor or IDE, a compiler, and a terminal. Only the compiler is essential. A version banner, in a terminal you opened yourself, proves the compiler is installed, and on the PATH. Terminals read PATH once, when they open, so after editing it, open a new one. And a working setup builds and runs the stub from the command line and from your environment, with the same line of output. Something to think about. Someone installs VS Code, opens a dot cpp file, and is surprised that nothing builds. What have they misunderstood?
About C++ Programming at UPI Study
C++ Programming (Computer Science 242) is a self-paced online course of 84 video lessons in 11 chapters, from your first program to decisions, loops, arrays, functions, classes, files, pointers and inheritance. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus Every course with PRO →
Why take it here
Why students take C++ Programming with UPI Study
Where the credit goes
Universities that work with NCCRS
C++ Programming carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About Preparing Your Machine
What three tools do I need to set up before I can run C++ code?
Why does my terminal say g++ is not found, and how do I fix PATH?
How do I compile and run a C++ file from the command line?
Which C++ compiler should I install: GCC, Clang, or MSVC?
About the C++ Programming course
How many college credits is C++ Programming?
How much does C++ Programming cost and what is included?
Which universities accept UPI Study credits?
How long does C++ Programming take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in C++ Programming.
84 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
3 credits · NCCRSEnroll →