CLANG(1)
π CLANG β the manual page, bestie edition πΈ
ok so this is the CLANG(1) page, like officially from the Clang section of the manual, and it's long, so hydrate first. We're doing this in parts. Part one is right here. Let's go. β¨
π NAME π
clang β the Clang C, C++, and Objective-C compiler. that's it, that's the whole name section, she's concise and she's iconic.
π¦ SYNOPSIS π¦
clang [options] filename ...
literally just: you, some options, and one or more *filename*s. the holy trinity. π«Ά
π DESCRIPTION π
ok so clang is a C, C++, and Objective-C compiler, and she does everything β preprocessing, parsing, optimization, code generation, assembly, and linking, all in one girl. no cap, the whole pipeline.
Depending on which high-level mode setting you pass, Clang will stop before doing a full link. So like, she can go all the way to a finished program, or she can clock out early if you tell her to. And because Clang is highly integrated (main character energy, she contains multitudes), it's genuinely important to understand the stages of compilation so you know how to invoke her properly. Here are the stages, in order, like a little compiler pipeline tour:
π Driver
The clang executable is actually a small driver which controls the overall execution of other tools such as the compiler, assembler and linker. She's the manager, not the worker, yk? Typically you do not need to interact with the driver, but you transparently use it to run the other tools. so you're always talking to her, but she's delegating. queen behavior.
βοΈ Preprocessing
This stage handles tokenization of the input source file, macro expansion, #include expansion and handling of other preprocessor directives. The output of this stage is typically called a ".i" (for C), ".ii" (for C++), ".mi" (for Objective-C), or ".mii" (for Objective-C++) file. yes the file extensions are a whole vibe, they're nesting like russian dolls.
π§ Parsing and Semantic Analysis
This stage parses the input file, translating preprocessor tokens into a parse tree. Once in the form of a parse tree, it applies semantic analysis to compute types for expressions as well and determine whether the code is well formed. This stage is responsible for generating most of the compiler warnings as well as parse errors. So when your build screams at you? this is her. she's the one doing the screaming. 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 to 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.
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!! she said why make a middleman file when I could simply not. π
π§ 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 dynamic library. The output of this stage is typically called an "a.out", ".dylib" or ".so" file.
π 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. she finds bugs before they happen, which is honestly terrifying and also slay.
β¨ OPTIONS β¨
π¬ Stage Selection Options
these tell Clang where to stop. pick your stopping point, bestie.
-Eβ Run the preprocessor stage. that's it. she stops right after preprocessing, nothing more.-fsyntax-onlyβ Run the preprocessor, parser and semantic analysis stages. so she checks your vibes (and your types) but produces nothing. pure judgment, no output.-Sβ Run the previous stages as well as 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 no stage selection option is specified, all stages above are run, and the linker is run to combine the results into an executable or shared library. basically: no notes, she does the whole thing, you get a real program. π₯
π£οΈ Language Selection and Mode Options
-x<language>β Treat subsequent input files as having type language. like a little name tag for your files.-std=<standard>β Specify the language standard to compile for. this one has lore, so buckle up:
Supported values for the C language are:
c89c90iso9899:1990
ISO C 1990
iso9899:199409
ISO C 1990 with amendment 1
gnu89gnu90
ISO C 1990 with GNU extensions
c99iso9899:1999
ISO C 1999
gnu99
ISO C 1999 with GNU extensions
c11iso9899:2011
ISO C 2011
gnu11
ISO C 2011 with GNU extensions
c17iso9899:2017
ISO C 2017
gnu17
ISO C 2017 with GNU extensions
c23iso9899:2024
ISO C 2023
gnu23
ISO C 2023 with GNU extensions
c2y
ISO C 202y
gnu2y
ISO C 202y with GNU extensions
The default C language standard is gnu17, except on PS4, where it is gnu99. (PS4 girlies stay on gnu99, respect.)
Supported values for the C++ language are:
c++98c++03
ISO C++ 1998 with amendments
gnu++98gnu++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 arelibstdc++andlibc++. If not specified, platform default will be used.-rtlib=<library>β Specify the compiler runtime library to use; supported options arelibgccandcompiler-rt. If not specified, platform default will be used.-ansiβ Same as-std=c89. that's the whole thing. retro queen.-ObjC,-ObjC++β Treat source input files as Objective-C and Object-C++ inputs respectively.-trigraphsβ Enable trigraphs. (yes, those. she's letting them in. π)-ffreestandingβ Indicate that the file should be compiled for a freestanding, not a hosted, environment. Note that a freestanding build still requires linking against a C Standard Library which supports the freestanding interfaces for the specified language mode and target environment. This includes functions likememcpy,memmove, andmemset. so like, freestanding β no library at all, don't get it twisted.-fno-builtinβ Disable special handling and optimizations of well-known library functions, likestrlen()andmalloc().-fno-builtin-<function>β Disable special handling and optimizations for the specific library function. For example,-fno-builtin-strlenremoves any special handling for thestrlen()library function.-fno-builtin-std-<function>β Disable special handling and optimizations for the specific C++ standard library function in namespacestd. For example,-fno-builtin-std-move_if_noexceptremoves any special handling for thestd::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. (don't use the std- one for those, ok? use the other one. iykyk.)
-fmath-errnoβ Indicate that math functions should be treated as updatingerrno.-fpascal-stringsβ Enable support for Pascal-style strings with"\pfoo".-fms-extensionsβ Enable support for Microsoft extensions.-fmsc-version=β Set_MSC_VER. When on Windows, this defaults to either the same value as the currently installed version ofcl.exe, or1933. Not set otherwise. (yes, the option is literally-fmsc-version=with nothing after it in the page, don't come for me, that's what it says. π)-fborland-extensionsβ Enable support for Borland extensions.-fwritable-stringsβ Make all string literals default to writable. This disables uniquing of strings and other optimizations. β οΈ you're giving up optimizations for this, so know what you're doing.-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 vectorsinteger: allow implicit bitcasts between integer vectors of the same overall bit-widthall: 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 girlies rise.-fobjc-abi-version=versionβ Select the Objective-C ABI version to use. Available versions are1(legacy"fragile"ABI),2(non-fragile ABI 1), and3(non-fragile ABI 2).-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.
π― 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's flexible like that, but like, check your build first bestie π«Ά
-arch<architecture>β Specify the architecture to build for (Mac OS X specific). mac girlies only for this one.-target<architecture>β Specify the architecture to build for (all platforms). everyone can have this one, it's for the whole group chat.
to be continuedβ¦ don't go anywhere π
-mmacos-version-min=<version>β building for macOS? this one tells clang the minimum version your app actually supports. set it, don't guess it π-miphoneos-version-minβ same vibe but for iPhone OS: it's the minimum version your app supports on that platform π±--print-supported-cpusβ prints out a whole list of supported processors for whatever target you picked (via--target=<architecture>or-arch <architecture>). no target specified? then it just rolls with the system default target, no big deal β¨-mcpu=?,-mtune=?β literally just an alias for--print-supported-cpus. same energy, different spelling π-mcpu=help,-mtune=helpβ yes bestie, also an alias for--print-supported-cpus. three whole ways to ask the same question π-march=<cpu>β tells Clang to generate code for a specific processor family member and later. like, if you hand it-march=i486, the compiler is fully allowed to emit instructions that are valid on i486 and everything after it β but which might not exist on the earlier ones. so choose your era wisely π--print-enabled-extensionsβ prints the extensions that are enabled for the target you get from combining--target,-march, and-mcpuvalues. heads up: right now it's only supported on AArch64 and RISC-V. on RISC-V it also prints out the ISA string of the enabled extensions, cute bonus πΈ--print-supported-extensionsβ prints every extension supported for every CPU target of an architecture (specified through--target=<architecture>or-arch <architecture>). no target? system default target, as always. also only supported on AArch64 and RISC-V currently, so don't come for it on other arches π
π₯ Code Generation Options π₯
-O0,-O1,-O2,-O3,-Ofast,-Os,-Oz,-Og,-O,-O4β pick your optimization level, bestie. here's the whole menu:-O0β means "no optimization." compiles the fastest and generates the most debuggable code. raw, unfiltered, iconic.-O1β somewhere between-O0and-O2. the middle child.-O2β moderate level of optimization that enables most optimizations. the reliable one.-O3β like-O2, except it also turns on optimizations that take longer to perform or that may generate larger code (all in an attempt to make the program run faster). highkey ambitious.-Ofastβ enables all the optimizations from-O3plus other aggressive optimizations that may violate strict compliance with language standards. this is deprecated in Clang 19 and a warning gets emitted telling you to use-O3in combination with-ffast-mathinstead if the non-standard math behavior is what you were actually after. there's no removal timeline yet β the whole point is to discourage-Ofastbecause an optimization flag changing the observable behavior of correct code is genuinely surprising. so likeβ¦ be careful π-Osβ like-O2with extra optimizations to reduce code size. smol but mighty.-Ozβ like-Os(and therefore like-O2), but reduces code size even further. extra smol.-Ogβ similar to-O1, but with slightly reduced optimization and better variable visibility. runs the same optimizations as-O1, but also sets the-fextend-variable-livenessflag, which tries to stop optimizations from reducing the liveness of your variables so they're actually available when you're debugging. debugging bestie rights π«Ά-Oβ equivalent to-O1. that's it, that's the whole sentence.-O4and higher β currently equivalent to-O3. (yes, really. no secret ultra mode. sorry π)
-g,-gline-tables-only,-gmodulesβ controls debug information output. quick note: Clang debug info works best at-O0. and when you pass more than one option starting with-g, the last one wins, so order matters:-gβ generate debug information. the classic.-gline-tables-onlyβ generates only line table debug information. this lets you get symbolicated backtraces with inlining information, but it does not include any info about variables, their locations, or their types. so backtraces: slay. variable inspection: nope.-gmodulesβ generates debug info that contains external references to types defined in Clang modules or precompiled headers, instead of emitting redundant debug type information into every single object file. this transparently switches the Clang module format to object file containers that hold the Clang module together with the debug information. when you're compiling a program that uses Clang modules or precompiled headers, this gives you complete debug info with faster compile times and much smaller object files. the glow-up is real β¨- > β οΈ do not use
-gmoduleswhen building static libraries for distribution to other machines, because the debug info will contain references to the module cache on the machine where the object files in the library were built. that path won't exist over there, and it will be a whole mess π
-fstandalone-debug,-fno-standalone-debugβ okay so Clang does a bunch of optimizations to shrink debug info in the binary, and they all rely on the assumption that debug type information can be spread across multiple compilation units. for example, Clang won't emit type definitions for types that a module doesn't need and that could be replaced with a forward declaration. further, Clang only emits type info for a dynamic C++ class in the module that contains the vtable for that class.-fstandalone-debugturns all those optimizations off. super useful when you're working with 3rd-party libraries that don't ship debug information. and fun fact: this is the default on Darwin. also note that Clang will never emit type information for types that aren't referenced by the program at all β that part is non-negotiable π-feliminate-unused-debug-typesβ by default, Clang doesn't emit type information for types that are defined but not used in a program. if you want to keep the debug info for those unused types, use the negation-fno-eliminate-unused-debug-types. keeping the strays, love that for them π-fexceptionsβ allows exceptions to be thrown through Clang-compiled stack frames (on many targets this enables unwind information for functions that might have an exception thrown through them). for most targets this is enabled by default for C++. so, y'know, C++ girlies are already covered π-ftrapvβ generates code to catch integer overflow errors. signed integer overflow is undefined in C, so with this flag, extra code gets generated to detect it and abort when it happens. no silent chaos allowed π¨-fvisibilityβ this flag sets the default visibility level. short and sweet.-fcommon,-fno-commonβ this flag specifies that variables without initializers get common linkage. you can turn it off with-fno-common. pick a lane bestie.-ftls-model=<model>β sets the default thread-local storage (TLS) model used 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 thetls_modelattribute, and the compiler will try to choose a more efficient model when it can. it's giving optimizer with initiative π-flto,-flto=full,-flto=thin,-emit-llvmβ generates output files in LLVM formats, suitable for link time optimization. when used with-Sthis generates LLVM intermediate language assembly files; otherwise it generates LLVM bitcode format object files (which may be passed to the linker depending on the stage selection options). the default for-fltois"full", where the LLVM bitcode is suitable for monolithic Link Time Optimization (LTO) β the linker merges all such modules into a single combined module for optimization. with"thin", ThinLTO compilation is invoked instead. two paths, both valid β¨
note: on Darwin, when you use-fltotogether with-gand you're compiling and linking in separate steps, you also need to pass-Wl,-object_path_lto,<lto-filename>.oat the linking step to tell theld64linker not to delete the temporary object file generated during Link Time Optimization. (Clang passes this flag to the linker automatically if compilation and linking happen in a single step.) doing this lets you debug the executable and generate the.dSYMbundle usingdsymutil(1). iykyk π¦
π Driver Options π
-###β print (but do not run) the commands that would run for this compilation. all the tea, none of the consequences π--helpβ display available options. the classic cry for guidance.-Qunused-argumentsβ do not emit any warnings for unused driver arguments. quiet quitting the nagging π-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. a true essential π-print-file-name=<file>β print the full library path of file.-print-libgcc-file-nameβ print the library path for the compiler runtime library currently in use ("libgcc.a"or"libclang_rt.builtins.*.a"). useful when you need to know exactly which one is getting linked π-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 map of where Clang goes looking πΊοΈ-save-tempsβ save intermediate compilation results. future you says thank you β¨-save-stats,-save-stats=cwd,-save-stats=objβ save internal code generation (LLVM) statistics to a file, either in the current directory (-save-stats/-save-stats=cwd) or in the directory of the output file (-save-state=obj). you can also control statistics reporting with environment variables: settingCC_PRINT_INTERNAL_STATto1enables the feature and the report goes to stdout in JSON format. settingCC_PRINT_INTERNAL_STAT_FILEto a file path makes it report statistics to that given file, also in JSON format.
psst β-save-statstakes precedence overCC_PRINT_INTERNAL_STATandCC_PRINT_INTERNAL_STAT_FILE. the flag wins, always π
-integrated-as,-no-integrated-asβ used to enable and disable, respectively, the integrated assembler. whether the integrated assembler is on by default is target dependent. so likeβ¦ check your target, bestie π-timeβ time individual commands. β±οΈ-ftime-reportβ print a timing summary of each stage of compilation. where did the time go? now you know π°οΈ-vβ show the commands to run and use verbose output. the talkative mode πΈ
π©Ί Diagnostics Options (yes bestie, how clang talks to you)
-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β okay so this whole little squad is about how Clang prints out info about diagnostics, aka your errors and warnings π. That's the entire vibe of the group. For the actual tea, go read the Clang User's Manual β it's all there, iykyk.
π§ͺ Preprocessor Options (the before-times, literally)
-D<macroname>=<value>β sneaks an implicit#defineinto the predefines buffer, and that buffer gets read before your source file is preprocessed. Pre-loading the lore, basically β¨-U<macroname>β same deal but the opposite energy: an implicit#undefinto the predefines buffer, read before the source file is preprocessed.-include <filename>β drops an implicit#includeinto the predefines buffer, read before the source file is preprocessed. Surprise header, but make it intentional π-I<directory>β adds the directory you name to the search path for include files.-F<directory>β adds the directory you name to the search path for framework include files.-nostdincβ nope, not searching the standard system directories or the compiler builtin directories for include files. None of them. Bye π-nostdlibincβ skips the standard system directories for include files, but does still search the compiler builtin include directories. Half a ghosting, not a full one π-nobuiltinincβ doesn't search clang's builtin directory for include files.-nostdinc++β doesn't search the system C++ standard library directory for include files. C++ girlies, this one's for you π¦-fkeep-system-includesβ the main character of this list ngl. Usable only with-E. It does not copy the preprocessed content of "system" headers into the output β instead it preserves the#includedirective. The way this can greatly reduce the volume of text produced by-E?? So helpful when you're trying to produce a "small" reproduceable test case π
β οΈ But bestie, listen: this option does not guarantee reproduceability. If the including source defines preprocessor symbols that influence the behavior of system headers (for example,_XOPEN_SOURCE), the operation of-Ewill remove that definition and thus can change the semantics of the included header. Also, using a different version of the system headers (especially a different version of the STL) may result in different behavior. Always verify the preprocessed file by compiling it separately. Fr fr, don't skip the vibe check on this one π
π ENVIRONMENT (the invisible hands, lowkey)
TMPDIR,TEMP,TMPβ these get checked in order for the location to write temporary files used during the compilation process. First one standing wins πCPATHβ specifies additional (non-system) header search paths used to find included header files. These paths are searched after paths specified with the-I<directory>option, but before any system header search paths. Paths are delimited by the platform dependent delimiter as used in thePATHenvironment variable. And here's the spicy bit: empty entries in the delimited path list β including those at the beginning or end of the list β are treated as specifying the compiler's current working directory πC_INCLUDE_PATH,OBJC_INCLUDE_PATH,CPLUS_INCLUDE_PATH,OBJCPLUS_INCLUDE_PATHβ these specify additional system header file search paths, used when processing the corresponding language. Search paths are delimited exactly as for theCPATHenvironment variable. Language-specific glow-up πMACOSX_DEPLOYMENT_TARGETβ if-mmacos-version-minis unspecified, the default deployment target is read from this environment variable. This option only affects Darwin targets. Apple-only behavior, no cap π
π BUGS (snitch era)
Found a bug? To report bugs, please visit <https://github.com/llvm/llvm-project/issues/>. Most bug reports should include preprocessed source files (use the -E option) and the full output of the compiler, along with information to reproduce. Give them the whole story, receipts and all π«Ά
π SEE ALSO
π Author
Maintained by the Clang / LLVM Team (<http://clang.llvm.org>)
Β©οΈ Copyright
2007-2026, The Clang Team
And that's a wrap on the whole page, bestie!! π This icon was brought to you by CLANG(1) β clang, section 21, dated May 15, 2026, in all its glory. Go forth and compile, you absolute legend πβ¨
π¦ where this page comes from
- fedora 44: clang21 21.1.8-5.fc44 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- fedora 44: clang21 21.1.8-5.fc44 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms