The described approach is working for me to link raylib to my actual zig project and use it within build an executable:
Now I try to build a static library from my zig project that depends on raylib, and export it also as a module (firefly). I used the following as a starting point:
My relevant build file code looks like:
const raylib_dep = b.dependency("raylib", .{
.target = target,
.optimize = optimize,
});
const firefly = b.addStaticLibrary(.{
.name = "firefly",
.root_source_file = .{ .path = "src/lib.zig" },
.target = target,
.optimize = optimize,
});
firefly.installHeadersDirectory(raylib_dep.path("src/"), "", .{
.include_extensions = &.{".h"},
});
firefly.linkLibrary(raylib_dep.artifact("raylib"));
firefly.linkLibC();
b.installArtifact(firefly);
const firefly_module = b.addModule("firefly", .{
.root_source_file = .{ .path = "src/lib.zig" },
});
firefly_module.addIncludePath(raylib_dep.path("src/"));
Then in another project I do like described within the article above, add the firefly dependency and try to link the firefly module like:
const firefly_dep = b.dependency("firefly", .{
.target = target,
// .optimize = optimize,
});
const firefly_module = firefly_dep.module("firefly");
const exe = b.addExecutable(.{
.name = "firefly-zig-example",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("firefly", firefly_module);
exe.linkLibrary(firefly_dep.artifact("firefly"));
On build I always get the following error:
C:\Users\anhef\AppData\Local\zig\p\12201eeeb3ea209ca3061915e81c73cb1f0257870884a6959927a9c052a2c1341dd1\src\inari\firefly\api\raylib\rendering.zig:3:12: error: C import failed
const rl = @cImport(@cInclude("raylib.h"));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
active_clear_color: C:\Users\anhef\AppData\Local\zig\p\12201eeeb3ea209ca3061915e81c73cb1f0257870884a6959927a9c052a2c1341dd1\src\inari\firefly\api\raylib\rendering.zig:168:30
initImpl: C:\Users\anhef\AppData\Local\zig\p\12201eeeb3ea209ca3061915e81c73cb1f0257870884a6959927a9c052a2c1341dd1\src\inari\firefly\api\raylib\rendering.zig:77:9
remaining reference traces hidden; use '-freference-trace' to see all reference traces
C:\Users\anhef\dev\zig-dev\firefly-zig-example\zig-cache\o\a7286b5c9fe6d89c1a5ce9384c6db9aa\cimport.h:1:10: error: 'raylib.h' file not found
#include <raylib.h>
^
I tried to play around with the paths but with no success. The raylib.h and other headerfiles seems to be present in the cache but are not found?
Thanks for any help.