gcc

Compiling

Compile and run (Enabling all warnings)

gcc -std=c11 -pedantic-errors -Wstrict-prototypes -Wall -Wextra -Werror q.c -o q.out && ./q.out

Automatically run and check for memory leaks

gcc -std=c11 -pedantic-errors -Wstrict-prototypes -Wall -Wextra -Werror q.c -o q.out && valgrind --leak-check=yes ./q.out

Change q.c and q.out

Options

Main

Option Description Link
-std=c11 Use C11 standard Link
-pedantic-errors Generate errors (not just warnings) if code is not following C11 standard
-Wstrict-prototypes Disallow things allowed in old C standards
-Wall Warn about anything the compiler finds shady Link
-Wextra Warn about things shadier than -Wall
-Werror Convert warnings to errors so that code with warnings can never be compiled
-o <output-file> Specify name of output file. (Defaults to a.out)

Separating each compilation step

Step name Option Input
file ext
Output
file ext
Description Link
Preprocess -E .c .i Replacing header files and preprocessor macros Link
Compile -S .i .s Preprocess C to Assembly Link
Assemble -c .s .o Assembly to binary/object files Link
Link -o .o .out Link individual object files into a single binary executable Link
To execute :
./<file-name>.out

To compile and execute in 1 command:

gcc <options> -o <file-name>.out && <file-name>.out

The && means the command on the command will only execute if the left command runs successfully

Single dot (.) = Current directory
Double dot (..) = Parent directory

The options tell the compiler on step to stop at. Which means that the later steps can accept previous file extensions.
For example, Link (-o) can accept .c

Stackoverflow

Checking libraries (like <stdio.h>)

List all libraries

cd /usr/include
ls

Opening a file

cd /usr/include
code <file-name>
Connected Pages
On this page
  • Compiling
    1. Compile and run (Enabling all warnings)
    2. Automatically run and check for memory leaks
  • Options
    1. Main
    2. Separating each compilation step
  • Checking libraries (like )
  • Relevant links