A macOS-specific C++ setup for VS Code, including zsh tips, SDKROOT handling, and build tasks for the freeCodeCamp C++ Programming Course.
Struggled with the setup for days? Been there, done that — here’s the result, which hopefully helps you get past this first obstacle.
⚠️ This template is intentionally macOS-specific. Windows users should follow the original freeCodeCamp setup.
⚠️ Note: This template works on my machine, but due to differences in VS Codesettings.jsonor environment setups, it might not run out-of-the-box on yours. If you run into issues, feel free to open an issue or contact me — I’ll do my best to help.
On macOS, there are a few differences compared to Windows/PowerShell in the shell commands and the build process. After installing all the compiler-related tools via Homebrew:
macOS uses zsh, not PowerShell:
-
Commands like
dirdo not exist. -
To list files and directories (including hidden ones) in the workspace:
ls -lhA
-
Optional alias to mimic PowerShell
dirper session:alias dir='ls -lhA'
macOS builds differ from Windows:
| Shell / OS | Binary Type | How to Run |
|---|---|---|
| zsh / macOS | Standard build task binary (e.g., rooster) |
./rooster |
| zsh / macOS | Per-file build binary (e.g., ${fileBasenameNoExtension}) |
./<filename> |
- macOS does not produce
.exefiles. - Always prepend
./to run a binary in the current directory.
-
Xcode Command Line Tools must be installed:
xcode-select --install
-
VS Code build tasks (.vscode/tasks.json) handle compilation automatically; you do not need to type compiler commands, but might want to change pats or naming of the created build to your liking.
-
Alternative compilers (Homebrew LLVM/clang, GNU g++) can be used in tasks.
-
For Homebrew Clang,
-isysroot ${SDKROOT}ensures SDK headers are found; Apple Clang and g++ generally do not require it.
- Apple Clang: usually no
-isysrootneeded. - Homebrew LLVM/clang:
-isysroot ${SDKROOT}recommended. - GNU g++: ignores
-isysrootunless explicitly configured.
-
Use the build task (per-file or full project).
-
Executable appears in workspace folder.
-
Run in zsh:
./<binary-name>
-
List workspace contents:
ls -lhA
| Concept | macOS Behavior |
|---|---|
| Shell | zsh (not PowerShell) |
| Listing files | ls -lhA or dir alias |
| Binary name | Standard: program / Per-file: <filename> |
| Running programs | ./binary-name |
| Compiler | Handled automatically by VS Code build tasks |
| SDKROOT | Used only for Homebrew Clang; Apple Clang / g++ usually not required |