Skip to main content

Synopsis

mcc [OPTIONS] <INPUT>

Required Arguments

INPUT
path
required
Path to the C source file to compile.Example:
mcc main.c

Output Options

--output
path
Specify the output file path for the compiled executable.Short form: -oDefault: Input filename without extensionExamples:
mcc -o myprogram main.c
mcc --output bin/server server.c
-S
flag
Generate and keep the assembly file after compilation.When specified:
  • Assembly file is saved with .s extension
  • Executable is still produced
  • Assembly file persists after linking
Output file naming:
  • If -o program is specified: program.s
  • If no -o flag: input.s (based on input filename)
Examples:
# Creates hello and hello.s
mcc -S hello.c

# Creates myapp and myapp.s
mcc -S -o myapp hello.c

Stage Control Options

Stop compilation at a specific stage. These flags are mutually exclusive.
--lex
flag
Stop after lexing (tokenization).Pipeline stages executed:
  1. Preprocessing
  2. Lexing ← stops here
Use case: Debug tokenization issuesExample:
mcc --lex input.c
--parse
flag
Stop after parsing.Pipeline stages executed:
  1. Preprocessing
  2. Lexing
  3. Parsing ← stops here
Use case: Debug syntax and parser issuesExample:
mcc --parse input.c
--tacky
flag
Stop after lowering to Three Address Code (TACKY) intermediate representation.Pipeline stages executed:
  1. Preprocessing
  2. Lexing
  3. Parsing
  4. Type checking
  5. Lowering to TACKY ← stops here
Use case: Debug semantic analysis and IR generationExample:
mcc --tacky input.c
--codegen
flag
Stop after code generation (assembly IR creation).Pipeline stages executed:
  1. Preprocessing
  2. Lexing
  3. Parsing
  4. Type checking
  5. Lowering to TACKY
  6. Code generation ← stops here
Use case: Debug assembly instruction generationExample:
mcc --codegen input.c

Target Options

--target
triple
Specify the target architecture triple for cross-compilation.Default: Host system’s default targetFormat: <arch>-<vendor>-<os>-<abi>Common targets:
  • x86_64-unknown-linux-gnu - 64-bit Linux (GNU)
  • x86_64-unknown-linux-musl - 64-bit Linux (musl)
  • x86_64-apple-darwin - macOS
  • aarch64-unknown-linux-gnu - ARM64 Linux
Examples:
# Cross-compile for Linux
mcc --target x86_64-unknown-linux-gnu main.c

# Compile for ARM64
mcc --target aarch64-unknown-linux-gnu main.c

Display Options

--color
choice
Control colored output for diagnostics and error messages.Choices:
  • auto - Enable colors if outputting to a terminal (default)
  • always - Always use colors
  • never - Never use colors
Default: autoExamples:
# Force colors (useful for piping with 'less -R')
mcc --color always main.c 2>&1 | less -R

# Disable colors (useful for CI/CD)
mcc --color never main.c

Environment Variables

The compiler respects the following environment variables:
CC
string
The C compiler to use for preprocessing and linking.Default: ccUsed for:
  • Running the C preprocessor
  • Assembling and linking object files
Examples:
CC=gcc mcc main.c
CC=clang mcc main.c
CC=/usr/local/bin/gcc-13 mcc main.c
Note: This is a hidden option not shown in --help output but can be overridden.
RUST_LOG
string
Control tracing and logging output for compiler internals.Default: warn,mcc=debug,mcc-syntax=debug,mcc-driver=debugLog levels: trace, debug, info, warn, errorExamples:
# Maximum verbosity
RUST_LOG=trace mcc main.c

# Only errors
RUST_LOG=error mcc main.c

# Debug specific crate
RUST_LOG=mcc_syntax=debug mcc main.c

# Multiple crates with different levels
RUST_LOG=warn,mcc=trace,mcc_syntax=debug mcc main.c

Flag Combinations

Valid Combinations

Many flags can be combined:
# Assembly output with custom executable name
mcc -S -o myprogram main.c

# Stage control with color output
mcc --parse --color always main.c

# Target specification with assembly output
mcc --target x86_64-unknown-linux-gnu -S main.c

# Output path with target
mcc -o bin/server --target x86_64-unknown-linux-gnu server.c

Invalid Combinations

Stage control flags are mutually exclusive:
# ERROR: Cannot specify multiple stage flags
mcc --parse --tacky main.c

# ERROR: Cannot combine stage flags
mcc --lex --codegen main.c

Exit Codes

0
exit code
Success - Compilation completed without errors
Non-zero
exit code
Failure - Compilation failed due to:
  • Syntax errors
  • Type errors
  • File I/O errors
  • Linker errors
  • Internal compiler errors

Examples

Basic Compilation

# Compile with default settings
mcc hello.c

# Compile with custom output name
mcc -o hello hello.c

Assembly Generation

# Keep assembly file
mcc -S factorial.c

# Keep assembly with custom name
mcc -S -o factorial factorial.c
# Creates: factorial (executable) and factorial.s (assembly)

Stage Debugging

# Check if parsing succeeds
mcc --parse program.c

# Check if type checking succeeds
mcc --tacky program.c

# Check if code generation succeeds
mcc --codegen program.c

Cross-Compilation

# Compile for specific target
mcc --target x86_64-unknown-linux-gnu main.c

# Cross-compile with assembly output
mcc --target aarch64-unknown-linux-gnu -S main.c

CI/CD Usage

# Disable colors for log files
mcc --color never main.c 2> build.log

# Use specific compiler
CC=gcc-12 mcc main.c

# Quiet compilation (errors only)
RUST_LOG=error mcc main.c

Development and Debugging

# Verbose tracing
RUST_LOG=trace mcc --tacky main.c

# Debug specific stage
RUST_LOG=mcc_syntax=debug mcc --parse main.c

# Keep all intermediate files with tracing
RUST_LOG=debug mcc -S -o debug_build main.c

Build docs developers (and LLMs) love