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
gcc app.c -o app
gccis 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:
gcc -Wall -Wextra app.c -o app
Standard selection
Modern C dialects add features. C11 is a common good default:
gcc -std=c11 app.c -o app
Debug builds
-g embeds debug info so you can use tools like breakpoints:
gcc -g app.c -o app
Optimization
Release builds get:
gcc -O2 app.c -o app
-O2 makes the code run faster. It's the everyday "speed up my program" flag.
Running
./app
TL;DR
gcc app.c -o appproduces the executable.-Wall -Wextraturn on important warnings.-std=c11peeks the language standard.-gis for debugging;-O2is for speed.