On this page
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
- > Translation Units, `extern` & Static vs. Shared Libraries
- > Why the C ABI Is the Lingua Franca of FFI
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
- Declaration (in
.h): tells the compiler a symbol's signature (int add(int a, int b);orextern int g_mode;). - Definition (in one
.c): allocates storage or emits machine code. - Static library (
.a): archive of.ofiles copied directly into the executable at link time (ar rcs libfoo.a foo.o). - Shared library (
.dylib/.so/.dll): loaded dynamically at runtime (cc -shared -fPIC foo.c -o libfoo.dylib).
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
- tuts/c/builtins/extern
- tuts/c/compilation_and_internals
- tuts/c/compilation_and_internals/build_pipeline_and_linking
- tuts/c/compilation_and_internals/preprocessor_and_macros
- tuts/c/fundamentals/control_flow_and_functions
- tuts/c/pointers_and_memory/undefined_behavior_and_sanitizers
- tuts/c/tutorials/c_shared_library_with_python_ctypes
- tuts/rust/ownership_and_internals
- tuts/rust/ownership_and_internals/unsafe_rust_and_ffi_abi
Related notes
- tuts/c/compilation_and_internals Linked here; links to this page; shared tags: #c, #compilers, #internals, #prog
- tuts/c/compilation_and_internals/preprocessor_and_macros Linked here; links to this page; shared tags: #c, #internals, #prog
- tuts/c/tutorials/c_shared_library_with_python_ctypes Linked here; links to this page; shared tags: #c, #prog
- tuts/c/builtins/extern links to this page; shared tags: #c, #prog
- tuts/c/fundamentals/control_flow_and_functions links to this page; shared tags: #c, #prog
- tuts/c/pointers_and_memory/undefined_behavior_and_sanitizers links to this page; shared tags: #c, #prog
- tuts/programming/memory_and_execution/compilation_interpretation_and_jit Linked here; shared tags: #compilers, #prog
- tuts/rust/ownership_and_internals links to this page; shared tags: #internals, #prog
- tuts/rust/ownership_and_internals/unsafe_rust_and_ffi_abi links to this page; shared tags: #internals, #prog
- tuts/python3/tutorials/advanced_python_internals/foreign_function_interfaces Linked here; shared tags: #internals