`zig cc -g` is ignoring me 😭

tldr: -g works with mingw, but not zig cc. Why?

I’m using Zig 0.16 now, but am open to try master.


Story time:

I fell into the Handmade Hero wormhole and started out using (on Arch Linux) x86_64-w64-mingw32-g++ and wine to follow along. So far so good.

x86_64-w64-mingw32-g++ -mwindows -g -o ./program.exe ./program.cpp
wine ./program.exe

I get pretty (~) pictures. Yay. I can even debug using winedbg --gdb --no-start ./program.exe and then connect to that with gf2 for a somewhat bearable debugging experience.

Omitting -g results in a (slightly) smaller executable (291K → 275K), so I see it having an effect.

Now I’d like to use Zig for C compilation instead. This works:

zig cc -target x86_64-windows-gnu -Wl,--subsystem,windows -g -o ./program.exe ./program.cpp -lgdi32
wine ./program.exe

The executable is a bit larger (776K) and comes with program.pdb (2.7M). Pictures are still pretty (~).

But I see no change whether I specify -g or not, or even replace it with -Doptimize=Debug (which I don’t think is even interpreted by zig cc the same way as zig build).

Why? And how do I influence the output of debug information for zig cc?

According to Andrew Kelley in 2022, Zig (and zig cc) does not have a -g flag and includes debugging symbols in binaries by default. You can use -s to remove debugging symbols.

Ah, good to know, thanks!