# How to use non build.zig built projects as dependencies?

**URL:** <https://ziggit.dev/t/how-to-use-non-build-zig-built-projects-as-dependencies/15868>\
**Category:** Help\
**Tags:** build-system\
**Created:** [June 2, 2026, 5:27am UTC](https://ziggit.dev/t/how-to-use-non-build-zig-built-projects-as-dependencies/15868 "2026-06-02T05:27:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Verafahn](https://ziggit.dev/user_avatar/ziggit.dev/verafahn/32/9285_2.png) [@Verafahn](https://ziggit.dev/u/Verafahn)\
**Post date:** [June 2, 2026, 5:27am UTC](https://ziggit.dev/t/how-to-use-non-build-zig-built-projects-as-dependencies/15868/1 "2026-06-02T05:27:33Z")

</div>

Zig also comes with a compilation toolchain for C/C++projects. Is there any way to make them dependencies in build.zig.zon without changing the original C/C++project?

Simply put, can Zig use projects built without build.zig as dependencies?

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [June 2, 2026, 5:33am UTC](https://ziggit.dev/t/how-to-use-non-build-zig-built-projects-as-dependencies/15868/2 "2026-06-02T05:33:33Z")

</div>

Yes it does, in fact this is often how zig bindings for c/c++ libraries are made, having the upstream library as a depedency.

Often they will port that project to the build system, but that is not necessary.

---

<div class="post-metadata">

**Author:** ![Kaeru](https://ziggit.dev/user_avatar/ziggit.dev/kaeru/32/3335_2.png) [@Kaeru](https://ziggit.dev/u/Kaeru)\
**Post date:** [June 2, 2026, 11:20am UTC](https://ziggit.dev/t/how-to-use-non-build-zig-built-projects-as-dependencies/15868/3 "2026-06-02T11:20:46Z")

</div>

You might find the project you want in [All Your Codebase · GitHub](https://github.com/allyourcodebase), these are just C / C++ projects that have been ported to the Zig build system.

I’ve also had some moderate success in using Zig only as a compiler for C++ projects and re-using a project’s cmake build system (just adding a preset that uses Zig as the C and C++ compiler). Moderate because I still have to use cmake which is _atrocious_.

You can also use system dependencies and link to those from your build.zig

---

<div class="post-metadata">

**Author:** ![raddari](https://ziggit.dev/user_avatar/ziggit.dev/raddari/32/991_2.png) [@raddari](https://ziggit.dev/u/raddari)\
**Post date:** [June 2, 2026, 3:53pm UTC](https://ziggit.dev/t/how-to-use-non-build-zig-built-projects-as-dependencies/15868/4 "2026-06-02T15:53:36Z")

</div>

Edit: this is expanding on the reply by @vulpesx regarding adding the upstream project as a dependency.

For _how_ to get the dependency, use `zig fetch --save=<name> <url>` to add it to your `build.zig.zon`. Then access it in your `build.zig` with `const dep = b.dependency("<name>", .{});`. From there you can e.g. `dep.path("some/path/to/foo.c")` to get a `LazyPath` to a file relative to the root of the fetched content.

This is pretty handy for grabbing small C projects or single file header libraries without vendoring them (at least one [stb](https://github.com/nothings/stb) header seems to find its way into most of my projects 😜). I can’t comment on how practical this is compared to forking + vendoring for larger projects such as SDL, however.

---

<div class="post-metadata">

**Author:** ![LucasSantos91](https://ziggit.dev/user_avatar/ziggit.dev/lucassantos91/32/440_2.png) [@LucasSantos91](https://ziggit.dev/u/LucasSantos91)\
**Post date:** [June 3, 2026, 1:24am UTC](https://ziggit.dev/t/how-to-use-non-build-zig-built-projects-as-dependencies/15868/5 "2026-06-03T01:24:58Z")

</div>

If you only need a couple of files, adding the repository to your build.zig.zon and accessing the files is quite easy, like others showed. But since you mentioned the fact that Zig has a C/C++ compiler, you are probably interested in large projects that use Make or CMake. Sadly, the answer is that you’re going to have to recreate their build process. People have already mention All Your Codebase. It’s great if the project you’re interested is already there, but if not, you can still use it as an example.  
For the most part, you’re going to add all C/C++ source files (.c, not .h) to a module, add all include paths and link whatever is necessary. Header files can be auto-translated via translate-c, or you can manually write your bindings. Zig can generate headers from templates (template.h.in), but you’re going to need to fill in the necessary details, most of which are features present in the host system or the target.  
I’m looking forward to the day someone is going to write a make and cmake emulator that can be baked into Zig. What a dream that would be.

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [June 3, 2026, 1:43am UTC](https://ziggit.dev/t/how-to-use-non-build-zig-built-projects-as-dependencies/15868/6 "2026-06-03T01:43:15Z")

</div>

I would still do this for large dependencies, the only time I would fork it is if I needed to change the source, or upstream is open to using the zig build system.

Whether you fork it or not, the process is almost identical.
