I’m trying to use stb_image.h, a C library fully contained in a single header file.
Here’s my build.zig:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "vulkan",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
exe.linkSystemLibrary("glfw");
exe.linkSystemLibrary("vulkan");
// Relevant:
exe.addCSourceFile(.{ .file = b.path("vendor/stb_image.h") });
exe.addIncludePath(b.path("vendor/"));
b.installArtifact(exe);
const shader_step = createShaderStep(b);
exe.step.dependOn(shader_step);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
// ... remainder truncated
zig build
fails with:
error: ld.lld: /home/joe/dev/vulkan/.zig-cache/o/f27ee214c582d247cd1583532d664e74/stb_image.o: unknown file type
error: the following command failed with 1 compilation errors:
/home/joe/.local/bin/zig build-exe -lglfw -lvulkan /home/joe/dev/vulkan/vendor/stb_image.h -ODebug -I /home/joe/dev/vulkan/vendor -Mroot=/home/joe/dev/vulkan/src/main.zig -lc --cache-dir /home/joe/dev/vulkan/.zig-cache --global-cache-dir /home/joe/.cache/zig --name vulkan --zig-lib-dir /home/joe/.local/lib/zig/ --listen=-
The file in question:
$ file .zig-cache/o/f27ee214c582d247cd1583532d664e74/stb_image.o
.zig-cache/o/f27ee214c582d247cd1583532d664e74/stb_image.o: LLVM Pre-compiled header file