clang-cpp
Preprocess C, C++, Objective-C, and Objective-C++ code
TLDR
View documentation for the original command
SYNOPSIS
clang-cpp [options] [input-file]
PARAMETERS
-D macro[=value]
Define macro before processing
-U macro
Undefine macro before processing
-I dir
Add include directory to search path
-include file
Process file as if #include "file" appears first
-std=standard
Language standard (e.g., c++20, gnu11)
-E
Preprocess only; write to stdout (default)
-o file
Write output to file
-P
Disable line markers in output
-nostdinc
Disable standard include directories
-Wno-warning
Suppress specific warnings
-fmodules
Enable modules support
-x language
Treat input as language (e.g., c++, objective-c)
-dM
Print macro definitions to stdout
--version
Print version information
-v
Verbose mode; show commands and search paths
DESCRIPTION
clang-cpp is the Clang implementation of the C/C++ preprocessor, part of the LLVM compiler infrastructure. It processes input source files by expanding macros, handling include directives, and tokenizing code, outputting preprocessed source without compiling it further.
Unlike the traditional cpp from GCC, clang-cpp uses Clang's superior parser for better diagnostics, stricter standard compliance, and modules support. It's ideal for build systems needing precise preprocessing, IDEs for code analysis, or generating dependencies. It supports C89 to C23 and C++98 to C++23 standards via -std= flags.
Invoke it like cpp, passing options for defines (-D), includes (-I), and output control. It inherits most options from clang with -E implied, emitting warnings for common issues like unused macros or include cycles. Performance is competitive, with excellent error messages aiding debugging.
CAVEATS
Not all clang backend options apply; focuses on preprocessing. May differ in macro expansion from GCC cpp in edge cases. Requires LLVM/Clang installation.
EXAMPLES
clang-cpp -I/usr/include file.c -o file.i
Preprocess file.c with includes, output to file.i.
clang-cpp -std=c++17 -DDEBUG file.cpp
Preprocess C++17 file with DEBUG macro.
EXIT STATUS
0 on success; non-zero on errors like invalid options or include failures.
HISTORY
Developed within the LLVM project starting 2007; clang-cpp introduced in Clang 3.0 (2012) as standalone tool. Evolved with Clang releases for better C++ support, modules (2013+), and modern standards.


