Home

CompilerFlags

CompilerFlags are options supplied to a compiler during the translation of source code into object or executable files. They influence how the code is parsed, optimized, diagnosed, and generated, and in some cases can affect linking behavior. Flags can be passed on the command line or defined in build systems and environment variables; common variables include CFLAGS for C, CXXFLAGS for C++, and CPPFLAGS for preprocessor settings.

Common categories of flags include: optimization levels such as -O0, -O1, -O2, -O3 and -Os; debugging aids

Notes on usage: flags are compiler-specific, and while many flags are shared across GCC and Clang, others

Example: gcc -O2 -g -Wall -std=c11 -I./include -L./lib -lm -o myprog main.c

like
-g;
warnings
and
error
handling
with
-Wall,
-Wextra,
and
-Werror;
language
standards
and
features
such
as
-std=c11
or
-std=c++17;
preprocessor
controls
such
as
-DNAME=value
and
-I
include-paths;
code
generation
and
architecture
selectors
like
-fPIC,
-march=native,
and
-m64;
and
linking
controls
such
as
-static,
-shared,
along
with
-L
library-path
and
-l
lib.
are
unique
to
a
particular
toolchain.
Incorrect
or
conflicting
flags
can
cause
compilation
failures
or
change
runtime
behavior.
Flags
are
typically
composed
and
propagated
through
build
systems
such
as
Make,
CMake,
Meson,
or
Bazel,
enabling
consistent
configuration
across
platforms.