How can I use the Zig build system to compile and debug a pure C++ project?

As mentioned, I am using VSCode + CodeLLDB.

My project is Sac-Zig-build.

Now I have a general understanding of the normal compilation process. When linkLibCpp() is called, it links to the libc++ that comes with Zig. When linkLibC() is called with -Dtarget=x86_64-windows-msvc, it links to MSVC.

However, debugging is almost unusable.

The situation when linking with Zig libc is as follows:


Normally, uparam as a String should be visible at a shallow level.

This looks like the debugger doesn’t have ‘natvis’ information (that’s what it’s called in the VStudio world, not sure what its called elsewhere), not sure if the Zig toolchain is supposed to provide that information though (probably not).

When linkLibCpp() is called, it links to the libc++ that comes with Zig. When linkLibC() is called with -Dtarget=x86_64-windows-msvc , it links to MSVC.

(nvm: see my reply below) AFAIK linkLibCpp() and linkLibC() are entirely different things (one is for the C++ stdlib, the other for the C stdlib) - e.g. linkLibC() should be unrelated to the problem you’re seeing.

First thing I would check is whether the combination of using a *-windows-msvc target and the Microsoft debugger via the VSCode MS C/C++ Extension works (e.g. not using CodeLLDB for debugging).

There’s also this ‘not-planned’ ticket which might be related: Add the ability to link Natvis files into PDBs · Issue #19646 · ziglang/zig · GitHub

PS: FWIW on macOS it “just works” with CodeLLDB (e.g. “cmdline” is a std::string):

This is using sokol-tools/build.zig at master ¡ floooh/sokol-tools ¡ GitHub which builds a pure C++ project.

…ah, now I know what you mean with linkLibCpp vs linkLibC, because I have this snippet in the build.zig:

    if (exe.rootModuleTarget().abi != .msvc) {
        exe.linkLibCpp();
    } else {
        exe.linkLibC();
    }

…I guess what this means is that msvc targets don’t have a linkable C++ stdlib (since everything is implemented in inline headers).

I haven’t tried debugging on Windows with this build.zig though.

Thank you for your reply. After my research, I found that this issue is actually very simple:Discord

1 Like