clang-cpp
Preprocess C, C++, Objective-C, and Objective-C++ code
TLDR
View documentation for the original command
SYNOPSIS
clang-cpp [options] input_file...
clang-cpp -E [options] input_file...
PARAMETERS
-E
Stop after the preprocessing stage and print the output to standard output. This is the primary behavior when invoking clang-cpp.
-I <dir>
Add directory dir to the list of directories to be searched for header files.
-D <macro>[=
Define a macro macro with an optional value (defaults to 1 if no value is given).
-U <macro>
Undefine the specified macro macro.
-P
Inhibit the generation of #line directives (line markers) in the preprocessed output.
-M
Generate a list of makefile dependencies for the source file.
-MM
Generate a list of makefile dependencies, omitting system headers.
-MD
Generate a dependency file suitable for make in addition to precompiling.
-MF <file>
When used with -M, -MM, or -MD, specify the name of the dependency file.
-MT <target>
When used with -M, -MM, or -MD, specify the target name for the dependency rule.
-x <language>
Treat subsequent input files as having type language (e.g., c++).
--help
Display a summary of command-line options.
--version
Display the version of Clang used.
DESCRIPTION
clang-cpp is a specialized invocation of the Clang compiler front-end, designed to perform only the preprocessing stage for C++ source code. As part of the LLVM project, Clang provides a modern, fast, and highly conformant compiler infrastructure.
When invoked as clang-cpp, it behaves much like the traditional cpp (C preprocessor), but specifically for C++ language constructs. Its primary function is to expand macros, include header files, and handle conditional compilation directives (#if, #ifdef, etc.), producing a single translation unit ready for the next compilation stages. It is often used for debugging preprocessing issues, generating dependency files for build systems, or preparing code for static analysis tools by providing a fully expanded source file.
CAVEATS
clang-cpp is typically a symlink to the clang executable, configured to default to C++ preprocessing. While it focuses solely on preprocessing, it still leverages the full C++ parsing capabilities of Clang, offering more robust error checking and language understanding than simpler preprocessors.
It assumes a C++ context by default, but this can be overridden with -x. It does not perform compilation, assembly, or linking; its output is the preprocessed source code.
<I>INTEGRATION WITH BUILD SYSTEMS</I>
clang-cpp's ability to generate dependency files via options like -M, -MM, and -MD makes it invaluable for build automation tools like make or Ninja. These dependency files ensure that source files are recompiled only when their direct or indirect dependencies (e.g., included headers) change, significantly optimizing build times.
<I>STATIC ANALYSIS AND TOOLING</I>
Because clang-cpp produces a single translation unit that fully resolves all macros and includes, it is an essential component for static analysis tools, code formatters, and refactoring engines built upon the Clang infrastructure. These tools can operate on the fully preprocessed code, simplifying their parsing and analysis logic.
HISTORY
Clang development began in 2007 at Apple Inc. to provide a modern, modular, and BSD-licensed alternative to GCC. clang-cpp emerged as part of this effort, offering a dedicated C++ preprocessor that benefits from Clang's advanced front-end architecture.
Its integration into the LLVM toolchain has made it a popular choice in various development environments, especially for C++ projects where precise preprocessing and strong adherence to C++ standards are crucial.