Skip to content
systemcoding.dev
Toolchains

Configure a debug build with meson setup --buildtype=debug

Configure a debug build directory with meson setup --buildtype=debug in Meson 1.6 and see which flags the buildtype expands into.

1 min read
Summarize in AI

In Meson the build type is a single option that stands for a bundle of two others, optimisation and debug information. Picking debug at setup time is one way to ask for -O0 -g.

Shell
meson setup build-debug --buildtype=debug
meson compile -C build-debug -v
Text
[1/2] cc -Ibuild-debug/demo.p -Ibuild-debug -I../src -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -O0 -g -MD -MQ demo.p/main.c.o -MF demo.p/main.c.o.d -o demo.p/main.c.o -c ../src/main.c

The -O0 -g at the end of the options come from the buildtype. The other values are debugoptimized (-O2 -g), release (-O3, no debug info) and minsize (-Os). Meson also supports plain, which adds no flags of its own and is the one distributions use so that their own CFLAGS apply. The table is in the buildtype reference.

Since Meson 1.0 the preferred form splits the two parts: -Doptimization=0 -Ddebug=true, and buildtype is a shorthand. Setting both at once is allowed, and the later explicit options win. Change the value later with meson configure, not by editing meson.build.

Taggedcmeson
Share

More snippets

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.