Before lesson 1
Setup guide
Fifteen minutes, once. You will install a C compiler, get the lesson files and run your first program from a terminal.
What you need
- A C compiler. Clang and GCC both work; on every system below the command
is called
cc. - A terminal, the text window where you type commands. Every lesson is compiled and run from one.
- A text editor for reading and changing the code. Any editor works; VS Code is a good free choice.
Lessons 1 to 25 and 36 to 38 are portable C and run anywhere. Lessons 26 to 35 use POSIX system calls or the ncurses library, so they need macOS, Linux, or Linux inside Windows (WSL). The instructions below set all of that up.
macOS
Open Terminal (in Applications, Utilities) and install Apple's command line
tools. They include the Clang compiler, make and ncurses:
$ xcode-select --install
A window asks you to confirm the download. When it finishes, check that the compiler answers:
$ cc --version
On macOS, gcc is another name for Clang. That is fine: every lesson compiles with
either.
Linux
Install the compiler, make and the ncurses headers with your package manager.
Debian, Ubuntu and Linux Mint:
$ sudo apt update
$ sudo apt install build-essential libncurses-dev
Fedora:
$ sudo dnf install gcc make ncurses-devel
Arch Linux:
$ sudo pacman -S base-devel ncurses
Then check that the compiler answers:
$ cc --version
Windows (WSL)
On Windows, take the course inside the Windows Subsystem for Linux: a real Ubuntu that runs next to Windows. Every lesson works there, including the POSIX and ncurses ones. Open PowerShell as administrator and run:
$ wsl --install
Restart when asked, then open Ubuntu from the Start menu and choose a user name and password. From then on you are on Linux: follow the Debian and Ubuntu steps above.
Your Windows drives appear inside Ubuntu under /mnt/ (for example /mnt/c/Users/you), but keep the lessons in your Ubuntu home folder, where
compiling is faster. VS Code with its WSL extension can edit files there directly.
Get the lesson files
Every lesson page has a Download button on each source file. To get the whole course at once, clone the repository with git:
$ git clone https://github.com/dunamismax/c-from-the-ground-up.git
$ cd c-from-the-ground-up
The folder names contain spaces, so put quotes around them when you change into one:
$ cd "Part 1 - The Beginner Path_ Core Concepts"
Your first program
In the folder that holds 1_hello_world.c, compile it, then run the program
the compiler made:
$ cc -Wall -Wextra -std=c17 -o 1_hello_world 1_hello_world.c
$ ./1_hello_world
If the terminal prints Hello, World!, you are ready. Head to Lesson 1: Hello, World! to learn what each line
of that program does.
What the flags mean
ccruns the C compiler.-Wall -Wextraturn on warnings. A warning is the compiler pointing at code that is legal but probably wrong. Read every one; the course's own code compiles with none.-std=c17picks the version of the C language standard to follow.-o namenames the program the compiler writes. Without it, you geta.out../nameruns a program from the current folder. The./is needed because the shell does not look for programs there by default.
Troubleshooting
cc: command not found- The compiler is not installed yet. Repeat the steps for your system above.
No such file or directory- You are not in the folder that holds the lesson file. Run
lsto see what is there, andcdinto the right folder. undefined reference to `pthread_create`(or tosqrt)- The lesson needs a library. Use the exact command on its lesson page; it includes
-pthread,-lmor-lncurseswhere needed. cannot find -lncursesorncurses.h: No such file- Install the ncurses development package (
libncurses-devorncurses-devel). Some systems call the libraryncursesw: try-lncursesw. - The program waits and nothing happens
- It is probably waiting for you to type something. Interactive lessons are marked on their page. Press Ctrl+C to stop any program.