Steps
Pre-processing
Expand compiler directives e.g. #define
, #include
Compilation
Compiles the .c
source code file to a .s
assembly code file
Assembly
Converts the .s
assembly code file to a .o
relocatable binary object code file. gcc
on Unix and Linux produces ELF object files
Linking
Links the .o
files together along with .a
and .so
library files to create a .out
executable file
The .o
files inside the .a
static library archive get embedded inside the resulting .out
file
The .so
files are not embedded but information about dynamically loaded libs is stored inside the resulting .out
file
C Standard Library libc.so
gets linked with every executable by GCC
implicitly. Others libs need to use the -l
option, e.g. libmylib.so
or libmylib.a
:
Runtime Linking
Performs dynamic linking of .so
library files during the execution of .out
file
The ldd
utility lists an executable file’s shared object dependencies: