I’m trying to import this sfml wrapper library into my project.I’ve added it to my build.zig.zon through zig fetch and then into the build.zig and was able to build my project, but when I try to run it I get the following error:
run command
zig run src/main.zig -lc -freference-trace=7
error:
src\main.zig:8:21: error: no module named 'sfml' available within module main
const sfml = @import("sfml");
^~~~~~
referenced by:
sfml: src\main.zig:11:18
usingnamespace_4: src\main.zig:16:20
sf: src\main.zig:10:12
main: src\main.zig:31:22
main: zig-path\lib\std\start.zig:656:37
comptime: zig-path\lib\std\start.zig:58:30
start: zig-path\lib\std\std.zig:97:27
1 reference(s) hidden; use '-freference-trace=8' to see all references
build.zig
const std = @import("std");
const sfml = @import("sfml");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "project",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
const dep = b.dependency("sfml", .{}).module("sfml");
exe.root_module.addImport("sfml", dep);
dep.addIncludePath(b.path("../CSFML/include/"));
exe.addLibraryPath(b.path("../CSFML/lib/msvc/"));
exe.linkLibC();
exe.linkSystemLibrary("csfml-graphics");
exe.linkSystemLibrary("csfml-system");
exe.linkSystemLibrary("csfml-window");
exe.linkSystemLibrary("csfml-audio");
const run = b.addRunArtifact(exe);
const run_step = b.step("run", "Run the game");
run_step.dependOn(&run.step);
}
main.zig
const sf = struct {
const sfml = @import("sfml");
usingnamespace sfml;
usingnamespace sfml.audio;
usingnamespace sfml.graphics;
usingnamespace sfml.window;
usingnamespace sfml.system;
};
pub fn main() !void {
var window = try sf.RenderWindow.create(.{ .x = 800, .y = 600 }, 32, "SFML Window", sf.Style.defaultStyle, null);
defer window.destroy();
while (window.isOpen()) {
while (window.pollEvent()) |event| {
if (event == .closed)
window.close();
}
window.clear(sf.Color.Black);
window.display();
}
}
Can someone explain how to solve this issue? I have the SFML and CSFML libraries in my project folder and the DLL files in my zig-out/bin folder.