Build types#
build types
.Predefined build types#
Standard build types are : Debug
, Release
, Release with Debug Information
and Minimum Size Release
.
Note
You can create your own easily. Feel free to be inspired by those shown below.
Different types are meant to alter the compilation flags to provide different binaries and other files, such as :
optimization level - if and how the code is optimized (speed, size)
debug informations - if must provide some data to be able to reuse the binaries and find the cause of a crash
assert and other outputs - if should disable the asserts or not, if the output is redirected somewhere or nulled
specific build tweaks - can enable better or faster FPU calculations, how the data is aligned, the dialect to use, enabling implicit conversions, language specifics warnings …
and many more …
In fact, the optimization level hides the use of multiple other flags that will tweak how the binaries are produced.
Optimization level#
-O/0/1/2/3/4, -Ofast, -Omin, -Os/z/g ...
.Optimization level flag |
Features |
---|---|
-O0 / none |
Straightforward compilation. No rearrangement. Debugging produce the expected result (even dead code is compiled). Default level. |
-O / -O1 |
Tries to reduce code size and execution time. No speed-space tradeoffs. No instruction scheduling (pipeline). May take longer to compile. Provide a good debug experience. |
-O2 |
Same as |
-O3 |
Further optimizations such as function inlining. If the L1 cache is big enough, the code may run faster. Otherwise, it will slow down since the same procedure may be composed of more instructions. |
-Os |
Aim for code size reduction, with near |
-Ofast |
Aim for the fastest code, with |
Note
Higher optimization levels (may) need more time to compile.
Warning
-O3
may create some problems if you rely on undefined behaviors, problems not seen with lower optimization levels.
Debug#
Debug
build aims to provide debuggable binaries.-O0
and -g
, to force no optimization and debug data output.Warning
You must run tests in Release
too. Since optimizations are applied, you must ensure that no bugs appear in your program.
Release with Debug Information#
Release with Debug Information
build aims to provide optimized, with debug info binaries.-O2
, -g
, and -DNDEBUG
to force great optimization, with debug info.Release#
Release
build aims to provide optimized binaries.-O3
and -DNDEBUG
to force great optimization.Minimum Size Release#
Minimum Size Release
build aims to provide optimized, while as small as possible binaries.-Os
and -DNDEBUG
to force great optimization while aiming for small size.