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
clangexecutable 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,
#includeexpansion, and handling of all the other preprocessor directives. the output of this stage is typically called a.ifile (for C), a.iifile (for C++), a.mifile (for Objective-C), or a.miifile (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
.sfile 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
.ofile 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.sofile. 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.oobject 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 1990iso9899:199409β ISO C 1990 with amendment 1gnu89,gnu90β ISO C 1990 with GNU extensionsc99,iso9899:1999β ISO C 1999gnu99β ISO C 1999 with GNU extensionsc11,iso9899:2011β ISO C 2011gnu11β ISO C 2011 with GNU extensionsc17,iso9899:2017β ISO C 2017gnu17β 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 amendmentsgnu++98,gnu++03β ISO C++ 1998 with amendments and GNU extensionsc++11β ISO C++ 2011 with amendmentsgnu++11β ISO C++ 2011 with amendments and GNU extensionsc++14β ISO C++ 2014 with amendmentsgnu++14β ISO C++ 2014 with amendments and GNU extensionsc++17β ISO C++ 2017 with amendmentsgnu++17β ISO C++ 2017 with amendments and GNU extensionsc++20β ISO C++ 2020 with amendmentsgnu++20β ISO C++ 2020 with amendments and GNU extensionsc++23β ISO C++ 2023 with amendmentsgnu++23β ISO C++ 2023 with amendments and GNU extensionsc++2cβ Working draft for C++2cgnu++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.0cl1.1β OpenCL 1.1cl1.2β OpenCL 1.2cl2.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. pick your fave, no wrong answers. π«Ά-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. 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 providememcpy,memmove,memset, andmemcmpimplementations, 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, likestrlen()andmalloc(). no special treatment, everyone's equal. π«-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. so targeted, so precise. π―-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. (important distinction bestie, don't mix them up! π)
-fmath-errnoβ Indicate that math functions should be treated as updatingerrno. 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 ofcl.exe, or1920. 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 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 blocks blocks, we love a block. π§±-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). 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 oni486and 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-O0and-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-O3along with other aggressive optimizations that may violate strict compliance with language standards. Yes bestie it's fast. Yes it's unhinged. π-Osβ like-O2with 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.-O4and 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-gis 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-typescan 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 thetls_modelattribute. 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-Sthis 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-fltoalong with-gand compiling and linking in separate steps, you also need to pass-Wl,-object_path_lto,<lto-filename>.oat the linking step to instruct theld64linker 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.dSYMbundle usingdsymutil(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.aorlibclang_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-statstake precedence overCC_PRINT_INTERNAL_STATandCC_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#defineinto the predefines buffer which is read before the source file is preprocessed.-U<macroname>β adds an implicit#undefinto the predefines buffer which is read before the source file is preprocessed.-include <filename>β adds an implicit#includeinto 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 thePATHenvironment 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 likeCPATHdoes, except they're only used when you're processing the appropriate language π so like,C_INCLUDE_PATHfor C things,CPLUS_INCLUDE_PATHfor 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
-Eoption 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>) π
π Copyright π
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
- ubuntu stonking: clang-17 1:17.0.6-23ubuntu10 Β· APACHE-2-LLVM-EXCEPTIONS
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms