Skip to content

Latest commit

 

History

History
63 lines (43 loc) · 1.86 KB

C Compilation Steps on Linux.md

File metadata and controls

63 lines (43 loc) · 1.86 KB
tags
Arch
OS

Steps

Pre-processing

Expand compiler directives e.g. #define, #include

gcc -E > out

Compilation

Compiles the .c source code file to a .s assembly code file

gcc -S prog.c

Assembly

Converts the .s assembly code file to a .o relocatable binary object code file. gcc on Unix and Linux produces ELF object files

gcc -c prog.c
objdump -d prog.o

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

gcc -o prog prog.c
objdump prog.out

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:

gcc -o prog prog.c -lmylib

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:

ldd prog.out

References