Compile and Run C++
Build Chemeketa project templates with Make. You can also run the compiler yourself to practice the complete command or diagnose a build problem.
Compiler commands by environment
| Environment | Compiler command |
|---|---|
| Codespaces | g++ |
| Windows | g++ |
| macOS with the required Homebrew GCC | g++-15 |
| Linux | g++ |
| WSL | g++ |
Compile one source file
Use the appropriate compiler command for your environment:
g++ -g -Wall -Wextra -std=c++20 main.cpp -o program.exe
On macOS, replace g++ with g++-15.
Compile every .cpp implementation file that belongs to the program. Do not list header
files as compiler inputs:
g++ -g -Wall -Wextra -std=c++20 main.cpp helper.cpp -o program.exe
Run the program
Bash in Codespaces, macOS, Linux, or WSL:
./program.exe
PowerShell on Windows:
.\program.exe
Build a template with Make
From the project folder, use:
| Environment | Command |
|---|---|
| Windows | mingw32-make |
| Codespaces, macOS, Linux, or WSL | make |
Template targets include:
make program.exe
make tests.exe
make clean
Not every template contains both executable targets. The Basic Project builds
program.exe, the Unit Test Project builds tests.exe, and the Combo Project builds
both.
To learn how Makefile rules, prerequisites, and targets work, continue to the Makefile Tutorial.
Common compiler options
-gincludes information needed by the debugger.-Wall -Wextraenables useful warnings.-std=c++20selects the course language standard.-o NAMEchooses the executable's filename.-I FOLDERadds a folder to the header search path.-ccompiles without linking an executable.