Loading lessons...
Compiling with GCC and Clang
Compiling with GCC and Clang
Compiling is the moment your text becomes a program. Let's look closely at the common options.
The base command
Bash
gcc app.c -o appgccis the compiler.app.cis the source.-o appnames the output executable (without it, Linux names ita.out).
Warning flags: your friends
Warnings catch bugs before they bite. Turn them on:
Bash
gcc -Wall -Wextra app.c -o appStandard selection
Modern C dialects add features. C11 is a common good default:
Bash
gcc -std=c11 app.c -o appDebug builds
-g embeds debug info so you can use tools like breakpoints:
Bash
gcc -g app.c -o appOptimization
Release builds get:
Bash
gcc -O2 app.c -o app-O2 makes the code run faster. It's the everyday "speed up my program" flag.
Running
Bash
./appTL;DR
gcc app.c -o appproduces the executable.-Wall -Wextraturn on important warnings.-std=c11peeks the language standard.-gis for debugging;-O2is for speed.