CLANG(1)
π CLANG(1) β the Clang C, C++, and Objective-C compiler π
okay bestie, sit down, grab a lil snack π β this is the clang manual page, part of the Clang manual, and it's a big one. But it's literally just your compiler, and your compiler is iconic, so let's go π
β¨ NAME β¨
clang β the Clang C, C++, and Objective-C compiler. that's it, that's the vibe π«Ά
πΈ SYNOPSIS πΈ
clang [options] filename ...
π DESCRIPTION π
so clang is a C, C++, and Objective-C compiler, and it's giving full stack β it encompasses preprocessing, parsing, optimization, code generation, assembly, and linking, all in one π« Depending on which high-level mode setting you pass, Clang will stop before doing a full link. And like, even though Clang is highly integrated (main character energy), it's genuinely important to understand the stages of compilation so you know how to invoke it properly. The stages are:
π Driver
the clang executable is actually just a small driver that controls the overall execution of other tools β the compiler, the assembler, the linker, all of them. Typically you don't need to interact with the driver directly, but you transparently use it to run the other tools. it's the manager, not the intern, iykyk.
π 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. so many lil extensions, we love a naming convention π
π§ Parsing and Semantic Analysis
this stage parses the input file, translating preprocessor tokens into a parse tree. Once it's in the form of a parse tree, it applies semantic analysis to compute types for expressions as well as determine whether the code is well formed. This stage is responsible for generating most of the compiler warnings as well as parse errors. The output of this stage is an "Abstract Syntax Tree" (AST). yes bestie, the AST β the moment your code becomes a whole tree π³
β‘ 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. lowkey a flex π₯
π§ 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. it's giving detective energy, we stan π΅οΈββοΈ
π OPTIONS π
π Stage Selection Options
like, how far do you wanna go down the pipeline? pick your stop bestie π
-Eβ Run the preprocessor stage.-fsyntax-onlyβ Run the preprocessor, parser and semantic analysis stages.-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. the full send π
π Language Selection and Mode Options
-x <language>β Treat subsequent input files as having type language.-std=<standard>β Specify the language standard to compile for. okay this one is a whole buffet, let's break it down π
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 extensionsc23,iso9899:2024β ISO C 2023gnu23β ISO C 2023 with GNU extensionsc2yβ ISO C 202ygnu2yβ ISO C 202y with GNU extensions
The default C language standard is gnu17, except on PS4, where it is gnu99. (PS4 bestie living in the past, no judgement π)
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 extensionsc++2dβ Working draft for C++2dgnu++2dβ Working draft for C++2d 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 fighter βοΈ-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 β¨-ObjC,-ObjC++β Treat source input files as Objective-C and Object-C++ inputs respectively.-trigraphsβ Enable trigraphs.-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" is not "no library at all" bestie, 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. (yes, the other one β the non-std flag. we know, it's a lil confusing π)
-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.-fborland-extensionsβ Enable support for Borland extensions.-fwritable-stringsβ Make all string literals default to writable. This disables uniquing of strings and other optimizations. β οΈ say bye to those optimizations, she's committing fr-flax-vector-conversions,-flax-vector-conversions=<kind>,-fno-lax-vector-conversionsβ Allow loose type checking rules for implicit vector conversions. Possible values ofkind: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.-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. so like, depending on your setup you might have a whole roster of targets, or literally just the one π
-arch <architecture>β Specify the architecture to build for (Mac OS X specific).-target <architecture>β tells Clang which architecture to build for, on every platform. π-mmacos-version-min=<version>β when you're building for macOS, this sets the minimum version your app supports. π-miphoneos-version-minβ when building for iPhone OS, this sets the minimum version your app supports. π±--print-supported-cpusβ prints 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 is used. π¨οΈ-mcpu=?,-mtune=?β acts as an alias for--print-supported-cpus. β¨-mcpu=help,-mtune=helpβ also acts as an alias for--print-supported-cpus. β¨-march=<cpu>β says Clang should generate code for a specific processor family member and later. For example, if you specify-march=i486, the compiler is allowed to generate instructions that are valid on i486 and later processors, but which may not exist on earlier ones. π₯--print-enabled-extensionsβ prints the list of extensions that are enabled for the target specified by the combination of--target,-march, and-mcpuvalues. Currently, this option is only supported on AArch64 and RISC-V. On RISC-V, this option also prints out the ISA string of enabled extensions. π--print-supported-extensionsβ prints the list of all extensions that are supported for every CPU target for an architecture (specified through--target=<architecture>or-arch <architecture>). If no target is specified, the system default target is used. Currently, this option is only supported on AArch64 and RISC-V. πΈ
π§ Code Generation Options π§
-O0,-O1,-O2,-O3,-Ofast,-Os,-Oz,-Og,-O,-O4β specify which optimization level to use:-O0means "no optimization": this level compiles the fastest and generates the most debuggable code. π’-O1is somewhere between-O0and-O2.-O2is a moderate level of optimization which enables most optimizations.-O3is 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). π-Ofastenables all the optimizations from-O3along with other aggressive optimizations that may violate strict compliance with language standards. This has been deprecated since Clang 19. There is no timeline yet for removal; the aim is to discourage use of-Ofastdue to the surprising behavior of an optimization flag changing the observable behavior of correct code. π If-Ofasthas been specified and is the effective optimization level (i.e. there is no later-Ooption specified), then the option can be replaced in the option string with-O3 -ffast-math -fstrict-aliasing. (-fstrict-aliasingis the default on non-Windows, non-UEFI platforms). If-Ofasthas been specified but is not the effective optimization level, then it can be removed or replaced with-O3.-Osis like-O2with extra optimizations to reduce code size.-Ozis like-Os(and thus-O2), but reduces code size further.-Ogis similar to-O1, but with slightly reduced optimization and better variable visibility. The same optimizations are run as at-O1, but the-fextend-variable-livenessflag is also set, which tries to prevent optimizations from reducing the liveness of user variables, improving their availability when debugging. π-Ois equivalent to-O1.-O4and higher β currently equivalent to-O3.
-g,-gline-tables-only,-gmodulesβ control debug information output. Note that Clang debug information works best at-O0. When more than one option starting with-gis specified, the last one wins:-ggenerates debug information. π-gline-tables-onlygenerates 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.-gmodulesgenerates 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. πΎ 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. π
-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.-fstandalone-debugturns 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. π§-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. π©Ή-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++. π’-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. π¨-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. π§΅-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-fltois"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. π
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). π«Ά
π Driver Options π
-###β print (but do not run) the commands to run for this compilation. π--helpβ display available options. π-Qunused-argumentsβ do not emit any warnings for unused driver arguments. π€«-Wa,<args>β pass the comma separated arguments inargsto the assembler. π οΈ-Wl,<args>β pass the comma separated arguments inargsto the linker. π-Wp,<args>β pass the comma separated arguments inargsto the preprocessor. π§ͺ-Xanalyzer <arg>β passargto the static analyzer. π¬-Xassembler <arg>β passargto the assembler. βοΈ-Xlinker <arg>β passargto the linker. π-Xpreprocessor <arg>β passargto the preprocessor. π§Ό-o <file>β write output tofile. π-print-file-name=<file>β print the full library path offile. π-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 ofname. π§-print-search-dirsβ print the paths used for finding libraries and programs. πΊοΈ-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-stats=obj). π You can also use environment variables to control the statistics reporting. SettingCC_PRINT_INTERNAL_STATto1enables the feature, the report goes to stdout in JSON format. SettingCC_PRINT_INTERNAL_STAT_FILEto 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. π-integrated-as,-no-integrated-asβ turns the integrated assembler on and off respectively. And whether it's already on by default? target dependent, bestie β it literally depends on where you're compiling π―-timeβ clocks each individual command so you can see where the time went β±οΈ-ftime-reportβ prints a lil timing summary for every stage of compilation. receipts for your build π₯-vβ shows the commands being run and gives you verbose output. the yapper flag π£οΈβ¨
π©Ί 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 lil squad controls how Clang prints out information about diagnostics (you know, errors and warnings π). For the full tea, the manpage says to check the Clang User's Manual β iykyk π
π§ Preprocessor Options π§
-D<macroname>=<value>β sneaks an implicit#defineinto the predefines buffer, which gets read before your source file is preprocessed. free real estate define π-U<macroname>β same energy, opposite direction: adds an implicit#undefinto the predefines buffer that's read before the source file is preprocessed π-include <filename>β adds an implicit#includeinto the predefines buffer, read before the source file is preprocessed. surprise include, but make it intentional π-I<directory>β adds the directory you point at to the search path for include files π-F<directory>β adds the directory to the search path for framework include files (yes, frameworks specifically) π-nostdincβ do not search the standard system directories or the compiler builtin directories for include files. full isolation era π«-nostdlibincβ skips the standard system directories for include files, but still does search compiler builtin include directories. so it's picky, not antisocial π«Ά-nobuiltinincβ don't search clang's own builtin directory for include files π βοΈ-nostdinc++β don't search the system C++ standard library directory for include files π¦-fkeep-system-includesβ usable only with-E. It does not copy the preprocessed content of"system"headers into the output; instead it preserves the#includedirective. This can massively shrink the volume of text-Eproduces, which is lowkey helpful when you're trying to make a "small" reproducible test case π
But bestie, hear me: this option does not guarantee reproducibility. 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. no cap, verify it π
π ENVIRONMENT π
TMPDIR,TEMP,TMPβ these environment variables get checked in order for the location to write temporary files used during the compilation process. first one wins, diva behavior π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, same as what's used in thePATHenvironment variable. Empty entries in the delimited path list β including ones 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 just like for theCPATHenvironment variable π§ββοΈMACOSX_DEPLOYMENT_TARGETβ if-mmacos-version-minis unspecified, the default deployment target is read from this environment variable. Heads up: this option only affects Darwin targets π
π BUGS π
To report bugs, please visit https://github.com/llvm/llvm-project/issues/ β that's the spot, bestie.
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 everything, main character energy, don't make them ask twice π«Ά
π 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 β slay, you read all of it π this edition is the 23 one, dated Oct 06, 2026, and it's signed CLANG(1). go forth and compile iconic things β¨π
π¦
π¦ where this page comes from
- centos-stream 9: clang 23.1.3-1.el9 Β· Apache-2.0 WITH LLVM-exception OR NCSA
- centos-stream 9: clang 23.1.3-1.el9 Β· 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