clang - the Clang C and Objective-C compiler
clang [-c|-S|-E] -std=standard -g [-O0|-O1|-O2|-Os|-O3|-O4] -Wwarnings... -pedantic -Idir... -Ldir... -Dmacro[=defn] -ffeature-option... -mmachine-option... -o output-file input-filenames
clang is a C and Objective-C compiler which encompasses preprocessing, parsing, optimization, code generation, assembly, and linking. Depending on which high-level mode setting is passed, Clang will stop before doing a full link. While Clang is highly integrated, it is important to understand the stages of compilation, to understand how to invoke it. These stages are:
The clang executable is actually a small driver which controls the overall execution of other tools such as the compiler, assembler and linker. Typically you do not need to interact with the driver, but you transparently use it to run the other tools.
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) or ".mi" (for Objective-C) file.
This stage parses the input file, translating preprocessor tokens into a parse tree. Once in the form of a parser 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. The output of this stage is an "Abstract Syntax Tree" (AST).
This stage translates an AST into low-level intermediate code or machine code (depending on the optimization level). This phase is responsible for optimizing the generated code and handling target-specfic code generation. The output of this stage is typically called a ".s" file.
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.
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.
The Clang compiler supports a large number of options to control each of these stages.
Display available options.
Print the commands to run for this compilation.
Only run the preprocessor.
Only run preprocess and compilation steps.
Only run preprocess, compile, and assemble steps.
Use the LLVM representation for assembler and object files.
Run the static analyzer. =item -ObjC++
Treat source input files as Objective-C++ inputs.
Treat source input files as Objective-C inputs.
Don't emit warning for unused driver arguments.
Pass the comma separated arguments in args to the assembler.
Pass the comma separated arguments in args to the linker.
Pass the comma separated arguments in args to the preprocessor.
Pass arg to the static analyzer.
Pass arg to the assembler.
Pass arg to the clang compiler.
Pass arg to the linker.
Pass arg to the preprocessor.
Write output to file.
Use pipes between commands, when possible.
Print the full library path of file.
Print the library path for "libgcc.a".
Print the full program path of name.
Print the paths used for finding libraries and programs.
Save intermediate compilation results.
Time individual commands.
Show commands to run and use verbose output.
Treat subsequent input files as having type language.
FIXME: Fill in environment.
It is inconceivable that Clang may have a bug.
FIXME: See also?
Maintained by the Clang / LLVM Team (http://clang.llvm.org).