Home

CXXFLAGS

CXXFLAGS is an environment variable and make variable used to specify flags for the C++ compiler when building software. It is commonly used in Makefiles and build scripts to customize compilation options for C++ source files and is often read by the CXX variable, which holds the compiler command. CXXFLAGS is distinct from CFLAGS (used for C compilation) and CPPFLAGS (preprocessor options) and from LDFLAGS (linker options). In many projects, CXXFLAGS is combined with user-provided flags so developers can influence builds without editing the build system.

Common options included in CXXFLAGS cover optimization, debugging, warnings, standards, and compiler-specific features. Typical flags are

Usage example: CXXFLAGS="-O2 -g -Wall -std=c++17" make. On Windows with non-GNU toolchains, the exact flag names

-O2
or
-O3
for
optimization,
-g
for
debugging
symbols,
-Wall
and
-Wextra
(often
with
-Werror
to
treat
warnings
as
errors),
and
-std=c++11,
-std=c++14,
-std=c++17,
or
-std=c++20
to
select
the
C++
standard.
Additional
flags
may
enable
or
disable
features,
such
as
-fPIC
for
position-independent
code,
-fno-exceptions
or
-fno-rtti,
and
various
-f
options.
Include
directories
and
defines
can
also
be
supplied
via
-I
and
-D
and
are
frequently
included
in
CXXFLAGS.
It
is
important
to
note
that
CXXFLAGS
affects
compilation
only;
linking
is
controlled
by
LDFLAGS
or
other
link-related
variables.
and
usage
may
differ,
as
MSVC
uses
different
options.
In
cross-platform
or
mixed
environments,
consider
portability
and
consult
project-specific
build
documentation.