Install C++
This page puts a C++ compiler on the machine and runs the file you already have. The introduction left pine.cpp with one writing line and named the screen word pine, but that page never started the program. The word was a prediction. Here you install g++ or clang++, compile that same file, and run it, so the prediction becomes a real line. Do not delete pine.cpp. Do not change the quoted word. Getting Started keeps this file and the lowercase word pine until a later page says the example changed.
Finished work is a version line from the compiler, then one program line: pine. The version line only proves the tool exists. The lesson result is pine. Leave a second writing line, a comment, and any new file for later. The next page is the first program. This page stops before that walk through writing the file.
A compiler reads pine.cpp and builds a program the machine can start. This course uses g++ or clang++. Both can build this file as C++17. You need one of them, not both. If g++ --version already prints a version line, the compiler is installed and you skip the download. If the terminal says the command cannot be found, install one compiler, close that terminal, and open the new one the installer expects. An old window often cannot see a tool that was added after it opened.
The file you compile is the one below. It is the introduction file, unchanged. main is still a function, not a class. The writing line is still std::cout << "pine" << std::endl; and return 0; still prints nothing. You are not rewriting it on this page. You are feeding it to the compiler.
#include <iostream>
int main()
{
std::cout << "pine" << std::endl;
return 0;
}
On Windows, check g++ --version in a terminal first. A version line means you can skip the installer and go to the build. If the command is missing, install MSYS2 from the MSYS2 site and open the UCRT64 terminal that comes with it, not the PowerShell window that was already open. In that UCRT64 terminal install the compiler with:
pacman -S --needed mingw-w64-ucrt-x86_64-gcc
Wait until pacman finishes. Then run g++ --version again in that same UCRT64 terminal. You want a version line. Stay in that terminal for the build. A PowerShell window from before the install still cannot see g++. Do not install a second compiler if this version line already appeared. Do not install a window toolkit or a game engine. The tool this page needs is g++.
On macOS the usual compiler is clang++, from Apple's command-line tools. In Terminal run:
xcode-select --install
Confirm the dialog and wait until it finishes. Quit Terminal if it was open during the install, then open Terminal again. Run clang++ --version. A version line means the tool is ready. Apple's package often does not provide a separate g++ command. When g++ is missing and clang++ prints a version, use clang++ for the build on this machine. The flag and the file stay the same. Only the tool name changes.
Do not run the macOS command on Windows or Linux. Do not run the Windows pacman line on a Mac. One machine, one installer, then the shared build.
On Linux the package name depends on the distro, and the command after that is the same. On Debian or Ubuntu run sudo apt update, then sudo apt install g++. On Fedora run sudo dnf install gcc-c++. When the package tool finishes, close the terminal and open a new one. Run g++ --version. A version line is the check. If the new terminal still cannot find g++, the package did not finish, or you are in a different environment than the one that received the package. Fix that before you compile. Do not edit pine.cpp to get past a missing compiler.
The shared build is the same on every system once the compiler answers. Move into the folder that contains pine.cpp. The folder name is yours. The file name is pine.cpp. From that folder the checked g++ commands are in the table. If your version check was clang++ instead of g++, swap the tool name and keep every other token: clang++ -std=c++17 pine.cpp -o pine and then ./pine.
📊 Commands that turn pine.cpp into a running program
| Step | Command on this page |
|---|---|
| Check | g++ --version |
| Build | g++ -std=c++17 pine.cpp -o pine |
| Run | ./pine |
| Screen | pine |
-std=c++17 tells the compiler to accept the course's language level. The number 17 is not printed. -o pine names the program pine. On Windows that file is often pine.exe, and ./pine still starts it inside the UCRT64 terminal. Without -o, many compilers write a.out or a.exe. Running that file still prints pine, but the checked command on this page uses -o pine so the program name matches the word.
Run ./pine from the same folder. The screen is one line:
pine
The quotes do not appear. main does not appear. The 0 from return does not appear. If you changed the quoted word to Pine, the screen is Pine and this page is not finished. Put the lowercase word back, build again, and run again.
Two failures show up before any word. If the terminal says pine.cpp does not exist, you are not in the folder that holds the file. The compiler does not search the whole disk for you. Move to that folder and repeat the build. If the terminal says g++ cannot be found, you are in the old window, or the install did not finish. Open the terminal that has the version line and repeat the build there. Neither failure is fixed by deleting the writing line.
Do not add a second std::cout line. Do not add a comment. Do not rename the file. Do not wrap main in a class. Getting Started still compiles this pine.cpp and still expects the lowercase word. A different file would be a different lesson.
The next page is the first program. It walks through writing this file, line by line, as the program itself. This page stops before that. You leave with a compiler that prints a version line, a pine.cpp that still has one writing line, and a run that shows pine. You do not leave with a second file, a keyboard read, or a new word on the screen.
Last pass: the version check is g++ --version, or clang++ --version when that is the tool you installed. The build is g++ -std=c++17 pine.cpp -o pine, with clang++ swapped in only when g++ is the missing one. The run is ./pine. The screen is pine. The first program page is next, and this page does not start it.
🧠 Test Your Knowledge
Test Your Knowledge
Challenge yourself with this interactive quiz and see how well you understand the topic
📝 Instructions
- Read each question carefully
- Select the best answer for each question
- You can retake the quiz as many times as you want
- Your progress will be shown at the top