Home

CMAKECXXCOMPILER

CMAKE_CXX_COMPILER is a CMake variable used to specify the C++ compiler that should be used for building a project. It is a cache variable that holds the path to the C++ compiler executable and can be set by the user through command line options, such as -DCMAKE_CXX_COMPILER, or by editing the CMake cache in an existing build directory.

When configuring a project, CMake relies on this variable to determine the C++ toolchain. If the variable

CMAKE_CXX_COMPILER is specific to the C++ language; there is a separate CMAKE_C_COMPILER for C. In multi-language

Changing the compiler after an initial configuration typically requires reconfiguring the project or starting a new

Example: cmake -S . -B build -DCMAKE_CXX_COMPILER=/usr/bin/clang++.

is
not
provided,
CMake
attempts
to
locate
a
suitable
C++
compiler
on
the
system
by
probing
common
tools
such
as
g++,
clang++,
or
cl.exe,
depending
on
the
platform
and
available
toolchains.
The
chosen
compiler
affects
supported
language
features,
available
standards,
and
the
flags
that
CMake
can
generate
for
the
build.
projects,
separate
compiler
variables
may
be
used
for
each
language.
The
variable
also
interacts
with
compiler
identification
variables
such
as
CMAKE_CXX_COMPILER_ID
and
CMAKE_CXX_COMPILER_VERSION,
which
CMake
sets
after
identifying
the
compiler.
build
directory,
since
an
existing
build
is
tied
to
the
previously
detected
toolchain.
This
variable
can
be
used
to
enable
cross-compilation
by
pointing
to
a
compiler
for
a
target
architecture.