CLANG(1)

πŸ’– CLANG(1) β€” the manual page, but make it make sense πŸ’–

okay so bestie, welcome to CLANG(1), the manual page for the Clang C, C++, and Objective-C compiler. she's iconic, she's built different, and by the end of this you're gonna be obsessed. let's get into it. 🫢


✨ NAME ✨

clang β€” the Clang C, C++, and Objective-C compiler. that's it, that's the name, periodt. πŸ‘‘


🌸 SYNOPSIS 🌸

clang [options] filename …

like, options first, files after, go off. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so clang is a C, C++, and Objective-C compiler, and she does EVERYTHING: preprocessing, parsing, optimization, code generation, assembly, and linking. the whole pipeline, no crumbs. Depending on which high-level mode setting you pass, Clang will stop before doing a full link β€” like she knows when to wrap it up, queen behavior.

but ngl, even though Clang is super highly integrated, it's actually important to understand the stages of compilation so you know how to invoke her. so here's the stage breakdown, bestie:

  • Driver β€” the clang executable is actually just a ✨small driver✨ that controls the overall execution of the other tools, like the compiler, the assembler, and the linker. Typically you don't need to interact with the driver directly, but you're transparently using it to run all those other tools. she's the manager, she's delegating, she's thriving. πŸŽ€
  • Preprocessing β€” this stage handles tokenization of the input source file, macro expansion, #include expansion, and handling of all the other preprocessor directives. the output of this stage is typically called a .i file (for C), a .ii file (for C++), a .mi file (for Objective-C), or a .mii file (for Objective-C++). cute extensions fr fr. πŸ“Ž
  • Parsing and Semantic Analysis β€” this stage parses the input file, translating preprocessor tokens into a parse tree. once it's in parse-tree form, it applies semantic analysis to compute types for expressions and to determine whether the code is well formed. this stage is responsible for generating most of the compiler warnings and the parse errors β€” so when the compiler is yelling at you, it's her. 😭 the output of this stage is an β€œAbstract Syntax Tree” (AST).
  • Code Generation and Optimization β€” this stage translates an AST into low-level intermediate code (known as β€œLLVM IR”) and ultimately into machine code. this phase is responsible for optimizing the generated code and handling target-specific code generation. the output of this stage is typically called a .s file or β€œassembly” file. lowkey the main character phase, ngl. πŸ‘‘

Clang also supports the use of an integrated assembler, in which the code generator produces object files directly. this avoids the overhead of generating the .s file and of calling the target assembler. efficiency slay. πŸ”₯

  • Assembler β€” this stage runs the target assembler to translate the output of the compiler into a target object file. the output of this stage is typically called a .o file or β€œobject” file. 🧚
  • Linker β€” this stage runs the target linker to merge multiple object files into an executable or a dynamic library. the output of this stage is typically called an a.out, .dylib, or .so file. she's bringing everyone together, she's the groupchat admin. 🫢

Clang Static Analyzer β€” the Clang Static Analyzer is a tool that scans source code to try to find bugs through code analysis. this tool uses many parts of Clang and is built into the same driver. Please see https://clang-analyzer.llvm.org for more details on how to use the static analyzer. bug-hunting queen behavior fr. πŸ”


πŸ’… OPTIONS πŸ’…

okay this is the part where we list literally every single flag, no skipping, no summarising, we eat every crumb. πŸ“

πŸŽ€ Stage Selection Options πŸŽ€

these tell Clang how far down the pipeline to go before she stops. pick your stopping point, bestie.

  • -E β€” Run the preprocessor stage. that's it, that's the whole journey. πŸ›‘
  • -fsyntax-only β€” Run the preprocessor, parser, and semantic analysis stages. no codegen, just vibes and opinions. 🧐
  • -S β€” Run the previous stages as well as the LLVM generation and optimization stages and target-specific code generation, producing an assembly file. ✍️
  • -c β€” Run all of the above, plus the assembler, generating a target .o object file. πŸ“¦
  • no stage selection option β€” if you don't specify a stage selection option, all of the stages above are run, and the linker is run to combine the results into an executable or shared library. the full send, the whole enchilada, the entire personality. πŸ’₯

🌈 Language Selection and Mode Options 🌈

  • -x <language> β€” Treat subsequent input files as having type language. speak her language, she'll speak yours. πŸ—£οΈ
  • -std=<standard> β€” Specify the language standard to compile for.

Supported values for the C language are:

  • c89, c90, iso9899:1990 β€” ISO C 1990
  • iso9899:199409 β€” ISO C 1990 with amendment 1
  • gnu89, gnu90 β€” ISO C 1990 with GNU extensions
  • c99, iso9899:1999 β€” ISO C 1999
  • gnu99 β€” ISO C 1999 with GNU extensions
  • c11, iso9899:2011 β€” ISO C 2011
  • gnu11 β€” ISO C 2011 with GNU extensions
  • c17, iso9899:2017 β€” ISO C 2017
  • gnu17 β€” ISO C 2017 with GNU extensions

The default C language standard is gnu17, except on PS4, where it is gnu99. (yes really, PS4 girlies get a different default, she's special like that. πŸ’€)

Supported values for the C++ language are:

  • c++98, c++03 β€” ISO C++ 1998 with amendments
  • gnu++98, gnu++03 β€” ISO C++ 1998 with amendments and GNU extensions
  • c++11 β€” ISO C++ 2011 with amendments
  • gnu++11 β€” ISO C++ 2011 with amendments and GNU extensions
  • c++14 β€” ISO C++ 2014 with amendments
  • gnu++14 β€” ISO C++ 2014 with amendments and GNU extensions
  • c++17 β€” ISO C++ 2017 with amendments
  • gnu++17 β€” ISO C++ 2017 with amendments and GNU extensions
  • c++20 β€” ISO C++ 2020 with amendments
  • gnu++20 β€” ISO C++ 2020 with amendments and GNU extensions
  • c++23 β€” ISO C++ 2023 with amendments
  • gnu++23 β€” ISO C++ 2023 with amendments and GNU extensions
  • c++2c β€” Working draft for C++2c
  • gnu++2c β€” Working draft for C++2c with GNU extensions

The default C++ language standard is gnu++17.

Supported values for the OpenCL language are:

  • cl1.0 β€” OpenCL 1.0
  • cl1.1 β€” OpenCL 1.1
  • cl1.2 β€” OpenCL 1.2
  • cl2.0 β€” OpenCL 2.0

The default OpenCL language standard is cl1.0.

Supported values for the CUDA language are:

  • cuda β€” NVIDIA CUDA(tm)
  • -stdlib=<library> β€” Specify the C++ standard library to use; supported options are libstdc++ and libc++. If not specified, platform default will be used. pick your fave, no wrong answers. 🫢
  • -rtlib=<library> β€” Specify the compiler runtime library to use; supported options are libgcc and compiler-rt. If not specified, platform default will be used. πŸ§ƒ
  • -ansi β€” Same as -std=c89. retro era, respect the classics. πŸ“Ό
  • -ObjC, -ObjC++ β€” Treat source input files as Objective-C and Objective-C++ inputs respectively. 🍎
  • -trigraphs β€” Enable trigraphs. they're giving ancient curse but okay, if you say so. πŸ§™
  • -ffreestanding β€” Indicate that the file should be compiled for a freestanding, not a hosted, environment. Note that it is assumed that a freestanding environment will additionally provide memcpy, memmove, memset, and memcmp implementations, as these are needed for efficient codegen for many programs. so like, bring your own snacks, but these four are mandatory. πŸŽ’
  • -fno-builtin β€” Disable special handling and optimizations of well-known library functions, like strlen() and malloc(). no special treatment, everyone's equal. 🚫
  • -fno-builtin-<function> β€” Disable special handling and optimizations for the specific library function. For example, -fno-builtin-strlen removes any special handling for the strlen() library function. so targeted, so precise. 🎯
  • -fno-builtin-std-<function> β€” Disable special handling and optimizations for the specific C++ standard library function in namespace std. For example, -fno-builtin-std-move_if_noexcept removes any special handling for the std::move_if_noexcept() library function.

For C standard library functions that the C++ standard library also provides in namespace std, use -fno-builtin-<function> instead. (important distinction bestie, don't mix them up! πŸ’€)

  • -fmath-errno β€” Indicate that math functions should be treated as updating errno. she's keeping receipts. 🧾
  • -fpascal-strings β€” Enable support for Pascal-style strings with \pfoo. blast from the past. πŸ•°οΈ
  • -fms-extensions β€” Enable support for Microsoft extensions. windows girlies, this one's for you. πŸͺŸ
  • -fmsc-version= β€” Set _MSC_VER. When on Windows, this defaults to either the same value as the currently installed version of cl.exe, or 1920. Not set otherwise. very specific, very demure. πŸŽ€
  • -fborland-extensions β€” Enable support for Borland extensions. deep cut fr. πŸ“š
  • -fwritable-strings β€” Make all string literals default to writable. This disables uniquing of strings and other optimizations. so you gain writability but you literally lose optimizations, trade-offs are real. 😭
  • -flax-vector-conversions, -flax-vector-conversions=<kind>, -fno-lax-vector-conversions β€” Allow loose type checking rules for implicit vector conversions. Possible values of <kind>:
    • none: allow no implicit conversions between vectors
    • integer: allow implicit bitcasts between integer vectors of the same overall bit-width
    • all: allow implicit bitcasts between any vectors of the same overall bit-width

<kind> defaults to integer if unspecified. ✨

  • -fblocks β€” Enable the β€œBlocks” language feature. blocks blocks blocks, we love a block. 🧱
  • -fobjc-abi-version=version β€” Select the Objective-C ABI version to use. Available versions are 1 (legacy β€œfragile” ABI), 2 (non-fragile ABI 1), and 3 (non-fragile ABI 2). choose your fighter. βš”οΈ
  • -fobjc-nonfragile-abi-version=<version> β€” Select the Objective-C non-fragile ABI version to use by default. This will only be used as the Objective-C ABI when the non-fragile ABI is enabled (either via -fobjc-nonfragile-abi, or because it is the platform default). πŸͺ„
  • -fobjc-nonfragile-abi, -fno-objc-nonfragile-abi β€” Enable use of the Objective-C non-fragile ABI. On platforms for which this is the default ABI, it can be disabled with -fno-objc-nonfragile-abi. on/off, toggle queen. πŸ”˜

πŸ‘‘ Target Selection Options πŸ‘‘

Clang fully supports cross compilation as an inherent part of its design. Depending on how your version of Clang is configured, it may have support for a number of cross compilers, or may only support a native target. she contains multitudes. 🌍

  • -target <architecture> β€” Specify the architecture to build for (all platforms). πŸ—οΈ
  • --print-supported-cpus β€” Print out a list of supported processors for the given target (specified through --target=<architecture> or -arch <architecture>). If no target is specified, the system default target will be used. window shopping for CPUs, iconic. πŸ›οΈ
  • -mcpu=?, -mtune=? β€” Acts as an alias for --print-supported-cpus. same energy, different spelling. πŸ’«
  • -mcpu=help, -mtune=help β€” Acts as an alias for --print-supported-cpus. yep, also this. πŸ™ˆ

and that's part 1 bestie β€” but hold on, we are so not done, there's more manual to eat, keep scrolling... πŸ’œ

  • -march=<cpu> β€” tell Clang which processor family member (and everything after it, bestie) it's allowed to target. Like, if you go -march=i486, the compiler gets to emit instructions that are valid on i486 and later CPUs β€” but which might not even exist on the earlier ones. Cute, right? Just don't run it on grandma's ancient box. πŸ’…

✨ Code Generation Options ✨

These are the main character knobs. Optimization levels, debug info, exception handling β€” the whole vibe. πŸŽ€

  • -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4 β€” pick your optimization level, girl:
    • -O0 β€” means β€œno optimization”. This level compiles the fastest and generates the most debuggable code. Zero notes, maximum honesty. 🫢
    • -O1 β€” somewhere between -O0 and -O2. The middle child.
    • -O2 β€” moderate level of optimization which enables most optimizations. The safe, default-ish slay. ✨
    • -O3 β€” like -O2, except that it enables optimizations that take longer to perform or that may generate larger code (in an attempt to make the program run faster). Speed over size, no cap.
    • -Ofast β€” enables all the optimizations from -O3 along with other aggressive optimizations that may violate strict compliance with language standards. Yes bestie it's fast. Yes it's unhinged. 😭
    • -Os β€” like -O2 with extra optimizations to reduce code size.
    • -Oz β€” like -Os (and thus -O2), but reduces code size further. Tiny icon.
    • -Og β€” like -O1. In future versions, this option might disable different optimizations in order to improve debuggability.
    • -O β€” equivalent to -O1.
    • -O4 and higher β€” currently equivalent to -O3. (The numbers go higher but the energy stays the same, iykyk.)
  • -g, -gline-tables-only, -gmodules β€” these control debug information output. πŸ“ Heads up: Clang debug information works best at -O0. And when more than one option starting with -g is specified, the last one wins (last one talking = the one who gets the aux, fr fr):
    • -g β€” generate debug information.
    • -gline-tables-only β€” generate only line table debug information. This allows for symbolicated backtraces with inlining information, but does not include any information about variables, their locations or types. So, backtraces? Slay. Variables? Ghosted. πŸ‘»
    • -gmodules β€” generate debug information that contains external references to types defined in Clang modules or precompiled headers instead of emitting redundant debug type information into every object file. This option transparently switches the Clang module format to object file containers that hold the Clang module together with the debug information. When compiling a program that uses Clang modules or precompiled headers, this option produces complete debug information with faster compile times and much smaller object files. Obsessed with the efficiency honestly. πŸ’–
This option should not be used when building static libraries for distribution to other machines because the debug info will contain references to the module cache on the machine the object files in the library were built on. Like, it'll be homesick for a computer that isn't yours. 🚫
  • -fstandalone-debug -fno-standalone-debug β€” Clang supports a number of optimizations to reduce the size of debug information in the binary. They work based on the assumption that the debug type information can be spread out over multiple compilation units. For instance, Clang will not emit type definitions for types that are not needed by a module and could be replaced with a forward declaration. Further, Clang will only emit type info for a dynamic C++ class in the module that contains the vtable for the class.

The -fstandalone-debug option turns off these optimizations. This is useful when working with 3rd-party libraries that don't come with debug information. This is the default on Darwin. Note that Clang will never emit type information for types that are not referenced at all by the program. Not even a little. πŸ™ˆ

  • -feliminate-unused-debug-types β€” by default, Clang does not emit type information for types that are defined but not used in a program. To retain the debug info for these unused types, the negation -fno-eliminate-unused-debug-types can be used. Give those unused types their moment. πŸ‘‘
  • -fexceptions β€” allow exceptions to be thrown through Clang compiled stack frames (on many targets, this will enable unwind information for functions that might have an exception thrown through them). For most targets, this is enabled by default for C++. It's giving "already on, bestie". 🌈
  • -ftrapv β€” generate code to catch integer overflow errors. Signed integer overflow is undefined in C. With this flag, extra code is generated to detect this and abort when it happens. It'll catch the crime and then, uh, immediately end the program. πŸ’€
  • -fvisibility β€” this flag sets the default visibility level.
  • -fcommon, -fno-common β€” this flag specifies that variables without initializers get common linkage. It can be disabled with -fno-common.
  • -ftls-model=<model> β€” set the default thread-local storage (TLS) model to use for thread-local variables. Valid values are: β€œglobal-dynamic”, β€œlocal-dynamic”, β€œinitial-exec” and β€œlocal-exec”. The default is β€œglobal-dynamic”. The default model can be overridden with the tls_model attribute. The compiler will try to choose a more efficient model if possible. Overachiever behavior, we love to see it. ⭐
  • -flto, -flto=full, -flto=thin, -emit-llvm β€” generate output files in LLVM formats, suitable for link time optimization. When used with -S this generates LLVM intermediate language assembly files, otherwise this generates LLVM bitcode format object files (which may be passed to the linker depending on the stage selection options).

The default for -flto is β€œfull”, in which the LLVM bitcode is suitable for monolithic Link Time Optimization (LTO), where the linker merges all such modules into a single combined module for optimization. With β€œthin”, ThinLTO <> compilation is invoked instead. Two flavors, both iconic. πŸ¦‹

Note: On Darwin, when using -flto along with -g and compiling and linking in separate steps, you also need to pass -Wl,-object_path_lto,<lto-filename>.o at the linking step to instruct the ld64 linker not to delete the temporary object file generated during Link Time Optimization (this flag is automatically passed to the linker by Clang if compilation and linking are done in a single step). This allows debugging the executable as well as generating the .dSYM bundle using dsymutil(1). Miss this step and your debug info just evaporates. Gone. Rude. 😭

πŸš— Driver Options πŸš—

These bad boys control the driver itself β€” the thing driving the whole operation. She's the main character, fr.

  • -### β€” print (but do not run) the commands to run for this compilation. A little preview, zero commitment. πŸ’…
  • --help β€” display available options.
  • -Qunused-arguments β€” do not emit any warnings for unused driver arguments. Let people live. πŸ™ˆ
  • -Wa,<args> β€” pass the comma separated arguments in args to the assembler.
  • -Wl,<args> β€” pass the comma separated arguments in args to the linker.
  • -Wp,<args> β€” pass the comma separated arguments in args to the preprocessor.
  • -Xanalyzer <arg> β€” pass arg to the static analyzer.
  • -Xassembler <arg> β€” pass arg to the assembler.
  • -Xlinker <arg> β€” pass arg to the linker.
  • -Xpreprocessor <arg> β€” pass arg to the preprocessor.
  • -o <file> β€” write output to file.
  • -print-file-name=<file> β€” print the full library path of file.
  • -print-libgcc-file-name β€” print the library path for the currently used compiler runtime library (libgcc.a or libclang_rt.builtins.*.a).
  • -print-prog-name=<name> β€” print the full program path of name.
  • -print-search-dirs β€” print the paths used for finding libraries and programs. A little tour of where everything lives. πŸ—ΊοΈ
  • -save-temps β€” save intermediate compilation results.
  • -save-stats, -save-stats=cwd, -save-stats=obj β€” save internal code generation (LLVM) statistics to a file in the current directory (-save-stats/-save-stats=cwd) or the directory of the output file (-save-state=obj).

You can also use environment variables to control the statistics reporting. Setting CC_PRINT_INTERNAL_STAT to 1 enables the feature, the report goes to stdout in JSON format.

Setting CC_PRINT_INTERNAL_STAT_FILE to a file path makes it report statistics to the given file in the JSON format.

Note that -save-stats take precedence over CC_PRINT_INTERNAL_STAT and CC_PRINT_INTERNAL_STAT_FILE. The flag is the one in charge, periodt.
  • -integrated-as, -no-integrated-as β€” used to enable and disable, respectively, the use of the integrated assembler. Whether the integrated assembler is on by default is target dependent.
  • -time β€” time individual commands. ⏱️
  • -ftime-report β€” print timing summary of each stage of compilation.
  • -v β€” show commands to run and use verbose output. She will not stop talking. We love her. πŸ’œ

πŸ” Diagnostics Options πŸ”

  • -fshow-column, -fshow-source-location, -fcaret-diagnostics, -fdiagnostics-fixit-info, -fdiagnostics-parseable-fixits, -fdiagnostics-print-source-range-info, -fprint-source-range-info, -fdiagnostics-show-option, -fmessage-length β€” this whole squad controls how Clang prints out information about diagnostics (errors and warnings). Please see the Clang User's Manual for more information. It's the girlies of error messaging, basically. πŸ’…

🧚 Preprocessor Options 🧚

Where the vibe gets defined before anything even runs. Very before-it-all. ✨

  • -D<macroname>=<value> β€” adds an implicit #define into the predefines buffer which is read before the source file is preprocessed.
  • -U<macroname> β€” adds an implicit #undef into the predefines buffer which is read before the source file is preprocessed.
  • -include <filename> β€” adds an implicit #include into the predefines buffer which is read before the source file is preprocessed.
  • -I<directory> β€” add the specified directory to the search path for include files.
  • -F<directory> β€” add the specified directory to the search path for framework include files.
  • -nostdinc β€” do not search the standard system directories or compiler builtin directories for include files.
  • -nostdlibinc β€” do not search the standard system directories for include files, but do search compiler builtin include directories. Er, actually, despite the name, that's what it does. Confusing, I know. 🫠
  • -nobuiltininc β€” do not search clang's builtin directory for include files.

🌸 ENVIRONMENT 🌸

okay so before you even get to the compiler proper, there's a whole little squad of environment variables that can mess with your build (affectionately) πŸ’– here's the lineup:

  • TMPDIR, TEMP, TMP β€” these three get checked in order to figure out where to write the temporary files that get used while your code is compiling πŸ—‚οΈ first one that's set wins, basically.
  • CPATH β€” if this one's present, it gets treated as a delimited list of paths that get added onto the default system include path list ✨ the delimiter is the platform dependent delimiter, same one you'd use in the PATH environment variable. iykyk.
empty components in this variable? ignored. gone. not a problem, bestie πŸ™ˆ
  • C_INCLUDE_PATH, OBJC_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJCPLUS_INCLUDE_PATH β€” these bad boys specify extra paths, working exactly like CPATH does, except they're only used when you're processing the appropriate language πŸ‘‘ so like, C_INCLUDE_PATH for C things, CPLUS_INCLUDE_PATH for C++ things, and so on. very much "right place, right vibe" energy.

πŸ’€ BUGS πŸ’€

found a bug? don't just scream into the void, bestie β€” go report it at <<https://github.com/llvm/llvm-project/issues/>> 🫢

and listen, most bug reports should include:

  • preprocessed source files (that's what the -E option is for, use it!)
  • the full output of the compiler
  • information to reproduce the thing

no cap, a report without those is giving "it doesn't work" and nothing else 😭 help them help you.


πŸ‘€ SEE ALSO πŸ‘€


✨ Author ✨

Maintained by the Clang / LLVM Team (<http://clang.llvm.org>) πŸ’œ

2007-2026, The Clang Team


and that's the whole page, bestie!! 🌈 this was CLANG(1), page 15, dated Sep 09, 2026, and honestly? she ate. go forth and compile something iconic πŸ‘‘βœ¨πŸ’…

πŸ“¦ where this page comes from