Lesson 115 +10 XP

Compiling and Running

Compiling and Running

The compiler turns .c source into a runnable program.

Typical commands

gcc hello.c -o hello
./hello

Flags

  • -o names the output file.
  • -Wall shows all warnings.
  • -g adds debug information.
  • -O2 optimizes for speed.

Warnings are your friends

gcc -Wall -o hello hello.c

Fix every warning; they become bugs later.

Link extra libraries

gcc prog.c -lm        # math library
gcc prog.c -lpthread  # threading

TL;DR

  • gcc source -o binary.
  • -Wall reveals issues.
  • -g enables debugging.
  • Link libraries with -l.