Setting Up a C Compiler
To run C you need a compiler: a program that turns your source code into an executable file. This lesson shows how to install GCC or Clang on Windows, macOS and Linux, compile your first program from the terminal, and choose an editor.
The main compilers
| Compiler | Command | Where |
|---|---|---|
| GCC (GNU Compiler Collection) | gcc | The standard on Linux; available everywhere |
| Clang (LLVM) | clang | The default on macOS; also on Linux and Windows |
| MSVC (Microsoft Visual C++) | cl | Windows, through Visual Studio |
GCC and Clang accept the same options, so the commands in this course work with either. On most systems the command cc runs whichever one is installed.
Installing
Linux
# Debian, Ubuntu, Linux Mint sudo apt update sudo apt install build-essential # Fedora sudo dnf install gcc make
macOS
Install Apple's Command Line Tools, which include Clang:
xcode-select --install
Windows
The simplest options:
- WSL (Windows Subsystem for Linux) — run
wsl --installin PowerShell, open Ubuntu, and follow the Linux steps. This gives you exactly the environment this course uses. - MSYS2 — installs GCC (the "UCRT64" toolchain) and a Unix-style terminal for native Windows programs.
- Visual Studio (Community edition) with the "Desktop development with C++" workload — includes MSVC, which compiles C too.
Checking the installation
gcc --version clang --version
Either one printing a version number means you're ready. Any GCC from version 8 or Clang from version 7 handles the C17 code in this course; the C23 lesson needs GCC 14 or Clang 18 or newer.
Compiling and running
Save this as hello.c:
#include <stdio.h> int main(void) { printf("Hello from my own computer!\n"); return 0; }
In a terminal, in the same folder, compile and run it:
gcc hello.c -o hello ./hello
Hello from my own computer!
-o hello names the output file; without it you get a.out (or a.exe on Windows). On Windows outside WSL, run it with hello.exe or .\hello.
The command this course uses
Always turn on warnings — they catch many bugs before your program ever runs:
gcc -std=c17 -Wall -Wextra -pedantic hello.c -o hello
| Option | Meaning |
|---|---|
-std=c17 | Use the C17 standard |
-Wall -Wextra | Enable most useful warnings |
-pedantic | Warn about anything that isn't standard C |
-o name | Name of the executable |
-g | Include debugging information (lesson 56) |
-O2 | Optimise for speed |
-lm | Link the maths library (needed on Linux for math.h, lesson 25) |
Every example in this course compiles with these options without a single warning.
Editors and IDEs
- Visual Studio Code with Microsoft's C/C++ extension (or the clangd extension) — a popular, lightweight choice.
- CLion, Visual Studio, Code::Blocks — full IDEs with a built-in debugger.
- Any text editor plus a terminal works perfectly well.
An IDE's green "Run" button just runs the same compile command for you. Learning the terminal command first makes errors much easier to understand.
No install? Use an online compiler
Online C compilers such as Compiler Explorer (godbolt.org) let you paste code and run it in a browser. They're handy for quick tests, though some don't support reading keyboard input.
Try it yourself
Install a compiler, then save this program as main.c and compile it with warnings on. Change the numbers and compile again.
7 apples shared by 3 friends: 2 each, 1 left over