On this page
  1. Build Pipeline, Linking & ABI
  2. Contents
  3. The Four-Stage C Build Pipeline
  4. Translation Units, extern & Static vs. Shared Libraries
  5. Why the C ABI Is the Lingua Franca of FFI

Build Pipeline, Linking & ABI

Prev: compilation_and_internals | Up: compilation_and_internals | Next: Preprocessor & Macros
Rel: Compilation, Interpretation & JIT, C Shared Library with Python ctypes, Python FFI (ctypes)
Ref: cppreference — Translation Phases
Tags: #public #prog #c #internals #compilers #abi


Contents


The Four-Stage C Build Pipeline

main.c + foo.h
  ├── 1. Preprocessor (cc -E)  -> Expands #include, #define, #ifdef into pure C (.i)
  ├── 2. Compiler     (cc -S)  -> Parses AST, optimizes IR, emits assembly (.s)
  ├── 3. Assembler    (cc -c)  -> Encodes machine instructions into relocatable object (.o)
  └── 4. Linker       (cc)     -> Resolves cross-file symbols & binds libc into executable/lib

Every .c file is compiled independently as one translation unit into a .o object file before the linker combines them.


Translation Units, extern & Static vs. Shared Libraries


Why the C ABI Is the Lingua Franca of FFI

The platform C Application Binary Interface (ABI) defines exact rules for symbol names (no name mangling), struct field padding, and which CPU registers pass arguments and return values. That stability is why Python (ctypes), Rust (extern "C"), Go (cgo), and OS kernels all interoperate through C headers and shared libraries.

Linked from

Related notes