Skip to content
Latchkey

clang: Usage, Options & Common CI Errors

clang is the LLVM front-end for C with fast builds and sharp diagnostics.

clang is largely gcc-compatible on the command line, which is why most Makefiles just swap CC=clang. The friction in CI is the small set of GCC-only flags clang rejects, and sanitizer runtime availability.

What it does

clang is the LLVM project C/Objective-C compiler front-end. It accepts most GCC-style flags, emits LLVM IR or native code, and is known for precise, colorized diagnostics and built-in sanitizers (ASan, UBSan, TSan, MSan).

Common usage

Terminal
clang -Wall -O2 main.c -o app
clang -c file.c -o file.o
clang -fsanitize=address,undefined -g main.c -o app
clang -Weverything -Wno-padded main.c        # very strict
clang --target=aarch64-linux-gnu main.c      # cross-compile

Options

FlagWhat it does
-c / -o <file>Compile only / name output
-I <dir> -L <dir> -l<name>Header / library paths and libs
-fsanitize=address|undefined|threadEnable a runtime sanitizer
-WeverythingTurn on (almost) every warning
--target=<triple>Cross-compile target triple
-O0/-O2/-Oz -gOptimization (Oz = smallest) / debug

Common errors in CI

clang: error: unknown argument: ‘-some-gcc-flag’ - a Makefile passing GCC-only options to clang; add -Wno-unknown-warning-option or drop the flag. With -fsanitize you may hit "ld: cannot find libclang_rt.asan" - install the compiler-rt package. "fatal error: ‘stdio.h’ file not found" in containers usually means no libc headers (install libc-dev) or a missing --sysroot when cross-compiling.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →