The best reference for using C libraries from Zig with the package manager that I’m aware of is @andrewrk’s personal project(s):
Using libsoundio
as the example, its build.zig
looks like this and it’s referenced in the build.zig
of the parent Zig project like this:
const soundio_dep = b.dependency("soundio", .{
.target = target,
.optimize = dep_optimize,
});
const libsoundio = soundio_dep.artifact("soundio");
which returns the static library, and is then linked via
player.linkLibrary(libsoundio);
For ffmpeg
, a different approach is taken where it adds a Zig wrapper module in its build.zig
that links the C static library, and then that’s whats used in the parent project.