cadence_learn
the_c++_track / level 01 of 15 ▶ 20 min

get your mac ready.

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.

after this level you'll be able to
  • Compile and run a C++ file from Terminal on your own Mac
  • Explain why g++ on a Mac is not really GNU g++
  • Avoid the three things that make code work at home and fail in the lab
before anything else

this part is fiddly, and it is not you

the one sentence

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.

why your laptop and the lab can disagree
YOUR MAC you type g++ …but you get Apple clang the name is a shim. It is a different compiler underneath. THE CLOSED LAB the same command …and you get real GNU g++ whatever the college installed, on their machines, not yours. MOSTLY the same 99% of the time WHERE THEY DISAGREE — and it is always in the direction that embarrasses you #include <bits/stdc++.h> · works in the lab, does not exist on a Mac · conio.h · system("pause") · Visual Studio project files Write it at home, hand it in, and it fails on their machine. Same code, different compiler — and it reads like you did something wrong.
This is the single most demoralising thing that happens in week one, and it has nothing to do with programming. Two compilers, mostly identical, that disagree at exactly the edges a beginner stumbles into.
do this once

twenty minutes, four steps

Open Terminal and get the compiler

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:

terminal
$ 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.

CHECK
Already installed? The command will say so. That is fine — move on.

Prove the compiler is there

Still in Terminal:

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.

NOTE
It says Apple clang, not GNU g++. That is expected and it is the thing to remember from this level — on a Mac, g++ is a nickname for Apple’s own compiler.

Get somewhere to write

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.

Make a folder you can find again

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.

terminal
$ mkdir -p ~/Documents/csci135/week01
$ cd ~/Documents/csci135/week01
# the prompt now shows you are inside that folder
WHY
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.
◈ ask an ai about this

“I am on a Mac and new to Terminal. Explain what xcode-select, g++, cd and ls each do, in plain English.”

chatgpt ↗ claude ↗

the important part

make your Mac agree with the lab

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.

rule 1 — always compile the same way

Use this exact command every single time, from day one:

terminal
$ 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.

rule 2 — never use these, whatever a tutorial says

#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.

rule 3 — ask what the lab actually uses, in week one

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.

◈ ask an ai about this

“What is the difference between Apple clang and GNU g++, and how do I avoid writing C++ that only works on my Mac?”

chatgpt ↗ claude ↗

when it goes wrong

the four things that actually happen

Pick what you saw. These four cover nearly everything that goes wrong at this stage.

▤ setup troubleshooter

Click whichever one matches what your Terminal said.

What went wrong?

do this together

set both machines up side by side

☶ two people · 25 minutes · two laptops

Do the four steps on both machines at the same time, out loud.

person a

Read each step aloud and run it on your machine first. Say exactly what appears, including anything that looks like an error.

person b

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.

what to keep

three things worth remembering

01

Setup trouble is not skill trouble

Nothing here is programming. It stops plenty of capable people, and it stops them for no good reason.

02

Always the same command

-std=c++17 -Wall, every time. The warnings are the half that catches silent mistakes.

03

Their machine decides the grade

Ask in week one what the lab compiles with, and match it. Nobody asks. It is fifteen seconds.

check yourself

3 questions before you move on

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.

▢ check yourself3 questions

Have a real go before revealing. Being wrong here is worth more than being right in three weeks.

01

You type g++ --version on a Mac and it answers "Apple clang version 21.0.0". Is something wrong?

02

Why compile with -Wall every single time?

03

You wrote code at home that uses #include <bits/stdc++.h> and it will not compile on your Mac. Why?

answered: 0 of 3right first time: 0
Stuck? Peter reads these personally and replies to your email.
Ask Peter →