Twenty minutes of plumbing, no programming. Do it now, calmly, rather than at 11pm before the first assignment — and make your laptop agree with the lab while you are at it.
g++ on a Mac is not really GNU g++Getting a Mac ready to compile C++ takes about twenty minutes, involves no programming whatsoever, and derails more people in week one than any actual concept in the course.
It derails them because it feels like it should be easy, so when it is not, it reads as evidence you are not cut out for this. It is not evidence of anything. It is plumbing — and once it is done you never think about it again.
You need three things: a compiler, somewhere to write, and a way to run what you wrote. Your Mac already has most of it.
Press ⌘ + space, type terminal, press return. A window of text appears — that is Terminal, and it is just another way of asking your Mac to do things. Type this and press return:
$ xcode-select --install
A box pops up asking to install the developer tools. Say yes and let it run — it is a few minutes and a couple of gigabytes. You do not need the full Xcode app, which is enormous. The command line tools alone are enough for this whole course.
Still in Terminal:
$ g++ --version Apple clang version 21.0.0 (clang-2100.1.1.101) Target: arm64-apple-darwin
The exact numbers will differ. What matters is that it answers at all.
g++ is a nickname for Apple’s own compiler.Download Visual Studio Code — free, from Microsoft, and what most of your class will be using. Open it, click the Extensions icon in the left bar, search C/C++, and install the one published by Microsoft.
You could use TextEdit. Do not — it saves formatting you cannot see, and the compiler will choke on it for reasons that are impossible to work out as a beginner.
One folder for the whole course, with one folder per assignment inside it. Sounds trivial. It is the difference between finding your week-three work in week eleven and not.
$ mkdir -p ~/Documents/csci135/week01 $ cd ~/Documents/csci135/week01 # the prompt now shows you are inside that folder
cd means “go into”. The compiler works on files where you currently are, so being in the right folder is most of what makes a command work or not.Your closed lab runs on the college’s machines, and they will not be Macs running Apple clang. That is fine 99% of the time. The other 1% is the part that ruins a week, so head it off now with three rules.
Use this exact command every single time, from day one:
$ g++ -std=c++17 -Wall yourfile.cpp -o yourprogram
-std=c++17 pins which version of the language you are writing, so your Mac and their machine agree on the rules. -Wall means warn me about everything — and that one is worth more than it looks. Some of the most common beginner mistakes are warnings, not errors: without -Wall your program compiles happily, runs, and does the wrong thing in silence.
#include <bits/stdc++.h> does not exist on a Mac and never will — it is a GNU shortcut. conio.h and system("pause") are Windows-only. Any tutorial using them was written for a different machine than yours, and following it will cost you an evening.
Ask your professor or the lab assistant which compiler and which C++ standard the marking uses. It is a fifteen-second question and almost nobody asks it. If their answer differs from -std=c++17, change yours to match theirs — their machine is the one that decides your grade.
Pick what you saw. These four cover nearly everything that goes wrong at this stage.
Click whichever one matches what your Terminal said.
What went wrong?
Read each step aloud and run it on your machine first. Say exactly what appears, including anything that looks like an error.
Run the same thing. When the two screens differ, stop and work out why before moving on.
Two machines is the whole point. Anything that differs between two Macs in the same room will differ far more between your Mac and the lab — and this is a cheap, calm rehearsal of the thing that will otherwise happen to you an hour before a deadline.
Nothing here is programming. It stops plenty of capable people, and it stops them for no good reason.
-std=c++17 -Wall, every time. The warnings are the half that catches silent mistakes.
Ask in week one what the lab compiles with, and match it. Nobody asks. It is fifteen seconds.
Not recall — these are the shapes an exam actually uses. Every answer below was produced by compiling and running the code, so if you disagree with one, the compiler is the one to believe.
Have a real go before revealing. Being wrong here is worth more than being right in three weeks.
You type g++ --version on a Mac and it answers "Apple clang version 21.0.0". Is something wrong?
Why compile with -Wall every single time?
You wrote code at home that uses #include <bits/stdc++.h> and it will not compile on your Mac. Why?
← back to the whole C++ track · stuck on anything? ask peter.