Hello, I am planning on using the zig vulkan bindings generator, but as an exercise, I wanted to try linking to my system’s vulkan loader through the build system and using the c headers first so I can develop my understanding.
On fedora, I installed the vulkan-loader
package. If I run rpm -ql vulkan-loader
, it lists the install paths for all of its files, which includes libvulkan.so.1
in several locations.
/etc/vulkan
/etc/vulkan/explicit_layer.d
/etc/vulkan/icd.d
/etc/vulkan/implicit_layer.d
/usr/lib/.build-id
/usr/lib/.build-id/98
/usr/lib/.build-id/98/7c6206801e376057ad9c0644a425621e6e7a38
/usr/lib64/libvulkan.so.1
/usr/lib64/libvulkan.so.1.4.313
/usr/share/doc/vulkan-loader
/usr/share/doc/vulkan-loader/CONTRIBUTING.md
/usr/share/doc/vulkan-loader/README.md
/usr/share/licenses/vulkan-loader
/usr/share/licenses/vulkan-loader/LICENSE.txt
/usr/share/vulkan
/usr/share/vulkan/explicit_layer.d
/usr/share/vulkan/icd.d
/usr/share/vulkan/implicit_layer.d
/etc/vulkan
/etc/vulkan/explicit_layer.d
/etc/vulkan/icd.d
/etc/vulkan/implicit_layer.d
/usr/lib/.build-id
/usr/lib/.build-id/a3
/usr/lib/.build-id/a3/2eaf56840c481778153de48194c409b35d9410
/usr/lib/libvulkan.so.1
/usr/lib/libvulkan.so.1.4.313
/usr/share/doc/vulkan-loader
/usr/share/doc/vulkan-loader/CONTRIBUTING.md
/usr/share/doc/vulkan-loader/README.md
/usr/share/licenses/vulkan-loader
/usr/share/licenses/vulkan-loader/LICENSE.txt
/usr/share/vulkan
/usr/share/vulkan/explicit_layer.d
/usr/share/vulkan/icd.d
/usr/share/vulkan/implicit_layer.d
However, zig build
reports that it cannot find the library when I attempt to link to vulkan
:
error: error: unable to find dynamic system library 'vulkan' using strategy 'paths_first'. searched paths:
/usr/local/lib64/libvulkan.so
/usr/local/lib64/libvulkan.a
/usr/local/lib/libvulkan.so
/usr/local/lib/libvulkan.a
/lib64/libvulkan.so
/lib64/libvulkan.a
/lib/libvulkan.so
/lib/libvulkan.a
/usr/lib64/libvulkan.so
/usr/lib64/libvulkan.a
/usr/lib/libvulkan.so
/usr/lib/libvulkan.a
As far as I can tell, this appears to be due to the .1
suffix at the end of the installed lib.
The main file is the default one created by zig init-exe. My build.zig
:
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const steps = .{
.run = b.step("run", "Run the app"),
.@"test" = b.step("test", "Run tests"),
};
const root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{},
});
root_module.linkSystemLibrary("vulkan", .{});
const exe = b.addExecutable(.{
.name = "learn_vulkan",
.root_module = root_module,
});
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
steps.run.dependOn(&run_cmd.step);
if (b.args) |args| {
run_cmd.addArgs(args);
}
const exe_tests = b.addTest(.{
.root_module = exe.root_module,
});
const run_exe_tests = b.addRunArtifact(exe_tests);
steps.@"test".dependOn(&run_exe_tests.step);
}
Question:
- Is this how I should link to the vulkan loader?
- How do I tell zig to look for the
.1
suffix? - Is
vulkan-loader
actually the right package?
I am not familiar what the best practices for using system libraries for software development, so I am a bit confused here. I also feel like I have vague memories of doing things like ln -s libfoo.so.1.4.3 libfoo.so
before to work around issues with applications expecting libraries without the version suffix. If anyone has some wisdom to share on this topic I would be very interested in understanding what is going on!