clang++
Compile C++ source code
TLDR
Compile a set of source code files into an executable binary
Activate output of all errors and warnings
Show common warnings, debug symbols in output, and optimize without affecting debugging
Choose a language standard to compile for
Include libraries located at a different path than the source file
Compile source code into LLVM Intermediate Representation (IR)
Optimize the compiled program for performance
Display version
SYNOPSIS
clang++ [options...] filename...
clang++ filename -o output [options]
PARAMETERS
-o file
Specify output filename
-c
Compile to object file only, no linking
-Idir
Add directory to include search path
-Ldir
Add directory to library search path
-lname
Link against library libname
-std=c++std
Language standard (e.g., c++11, c++20, gnu++17)
-Olevel
Optimization level (0-3, s, z, fast)
-g
Generate debug information
-Wall
Enable most common warnings
-Werror
Treat warnings as errors
-Dmacro[=def]
Define macro
-Umacro
Undefine macro
-fPIC
Generate position-independent code
-shared
Create shared object file
-pthread
Support POSIX threads
-fuse-ld=linker
Use specified linker (lld, bfd)
-march=arch
Target architecture (native, x86-64)
-mtune=tune
Optimize for specific CPU
--version
Print version information
-v
Verbose output, show commands
-E
Preprocess only
-M
Generate dependency file
-MMD
Like -M but ignore system headers
-fmodules
Enable C++ modules
-stdlib=lib
C++ standard library (libc++, libstdc++)
DESCRIPTION
clang++ is the C++ compiler driver from the LLVM/Clang project, designed as a drop-in replacement for g++. It compiles C++ source code into executables or object files, leveraging LLVM's modular infrastructure for optimization and code generation. Key advantages include faster compilation speeds, superior diagnostics with fix-it hints, and excellent GCC compatibility. It supports modern C++ standards like C++20 and C++23, modules, and OpenMP. clang++ automatically selects the appropriate language mode for C++ files (.cpp, .cxx, etc.) and invokes the clang frontend with -std=c++ defaults. It integrates seamlessly with build systems like CMake and supports cross-compilation for various architectures. Widely used in projects prioritizing performance and developer experience, such as Chrome, Firefox, and LLVM itself.
Unlike GCC, Clang produces human-readable IR and emphasizes modular design, enabling tools like static analyzers. It handles linking via lld or system linkers.
CAVEATS
Some GCC extensions not fully supported; linker defaults to system linker (use -fuse-ld=lld for LLVM linker). Requires LLVM/Clang installation. Modular headers experimental in some versions. Cross-compilation needs target triples.
EXAMPLES
clang++ main.cpp -o main -std=c++20 -O2 -Wall
clang++ -c file.cpp -I/usr/include/extra
RESOURCES
Man page: man clang++
Official docs: clang.llvm.org
Help: clang++ --help
HISTORY
Developed by Chris Lattner at Apple starting 2007 as part of LLVM; first public release 2010. Became production-ready for C++ around 2012. Apple adopted for Xcode; now default in FreeBSD. Reached GCC-8 parity by 2018. Actively maintained by LLVM Foundation with contributions from Google, Intel, etc.
SEE ALSO
clang(1), gcc(1), g++(1), lld(1), llvm-config(1)


