GCC Cheat Sheet

For the sake of example. We are going to have two files program.c and library.c. program.c uses functions defined in library.c. TODO:ADD HEADER FILES

GCC

$ gcc program.c library.c -o program

Generates .o executable file

Compilation

$ gcc -S program.c
$ gcc -S library.c

Generates text .s assembly files

Assembly

$ as program.s -o program.o
$ as library.s -o library.o
or
$ gcc -c program.c -o program.o

Generates .o machine language assembly object files

Linking

$ ld program.o library.o -o program
or
$ gcc program.o library.o

Links object files together and creates executable file

Resources

The following resources were used while writing this page

  • http://codingfreak.blogspot.com/2008/02/compilation-process-in-gcc.html
  • http://cs-fundamentals.com/c-programming/how-to-compile-c-program-using-gcc.php