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

**URL:** <https://ziggit.dev/t/how-can-i-use-the-zig-build-system-to-compile-and-debug-a-pure-c-project/10287>\
**Category:** Help\
**Tags:** c, build-system, debugger\
**Created:** [May 28, 2025, 3:28am UTC](https://ziggit.dev/t/how-can-i-use-the-zig-build-system-to-compile-and-debug-a-pure-c-project/10287 "2025-05-28T03:28:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![inschrift.spruch](https://ziggit.dev/user_avatar/ziggit.dev/inschrift.spruch/32/5469_2.png) [@inschrift.spruch](https://ziggit.dev/u/inschrift.spruch)\
**Post date:** [May 28, 2025, 3:28am UTC](https://ziggit.dev/t/how-can-i-use-the-zig-build-system-to-compile-and-debug-a-pure-c-project/10287/1 "2025-05-28T03:28:43Z")

</div>

As mentioned, I am using VSCode + CodeLLDB.

My project is [Sac-Zig-build](https://github.com/inschrift-spruch-raum/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:

 ![Code_Ew14xZ1sXz](https://ziggit.dev/uploads/default/original/2X/4/473e7fc2cb1bb1039983fee0ef220aca5928838c.png)  
Normally, `uparam` as a `String` should be visible at a shallow level.

---

<div class="post-metadata">

**Author:** ![floooh](https://ziggit.dev/user_avatar/ziggit.dev/floooh/32/2989_2.png) [@floooh](https://ziggit.dev/u/floooh)\
**Post date:** [May 28, 2025, 9:14am UTC](https://ziggit.dev/t/how-can-i-use-the-zig-build-system-to-compile-and-debug-a-pure-c-project/10287/2 "2025-05-28T09:14:12Z")

</div>

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](https://github.com/ziglang/zig/issues/19646)

---

<div class="post-metadata">

**Author:** ![floooh](https://ziggit.dev/user_avatar/ziggit.dev/floooh/32/2989_2.png) [@floooh](https://ziggit.dev/u/floooh)\
**Post date:** [May 28, 2025, 9:25am UTC](https://ziggit.dev/t/how-can-i-use-the-zig-build-system-to-compile-and-debug-a-pure-c-project/10287/3 "2025-05-28T09:25:52Z")

</div>

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

 ![image](https://ziggit.dev/uploads/default/original/2X/7/70ee5d3d23e28dad049efb39cc82fcc0d3ce76eb.png)

This is using [sokol-tools/build.zig at master · floooh/sokol-tools · GitHub](https://github.com/floooh/sokol-tools/blob/master/build.zig) 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:

```ts
    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.

---

<div class="post-metadata">

**Author:** ![inschrift.spruch](https://ziggit.dev/user_avatar/ziggit.dev/inschrift.spruch/32/5469_2.png) [@inschrift.spruch](https://ziggit.dev/u/inschrift.spruch)\
**Post date:** [May 28, 2025, 10:48am UTC](https://ziggit.dev/t/how-can-i-use-the-zig-build-system-to-compile-and-debug-a-pure-c-project/10287/5 "2025-05-28T10:48:51Z")

</div>

Thank you for your reply. After my research, I found that this issue is actually very simple:[Discord](https://discord.com/channels/605571803288698900/1376889976951668816/1377233389551358042)
