No module named 'xx1' available within module xx2

I created three zig projects in the same level directory

lib: xx1

lib: xx2 import xx1
    .dependencies = .{
        .xx1 = .{ .path = "../xx1" },
    },

bin: xx3 import xx1 and xx2
    .dependencies = .{
        .xx1 = .{ .path = "../xx1" },
        .xx2 = .{ .path = "../xx2" },
    },

Running zig build in the root directory of the xx3 project gives an error ‘no module named ‘xx1’ available within module xx2’

Something like the following should establish the dependency graph you describe.

In xx1 build.zig:

_ = b.addModule("xx1", .{
    .root_source_file = .{ .path = "src/root.zig" },
});

In xx2 build.zig:

const xx1_module = b.dependency("xx1", .{}).module("xx1");

_ = b.addModule("xx2", .{
        .root_source_file = .{ .path = "src/root.zig" },
        .imports = &.{
            .{ .name = "xx1", .module = xx1_module },
        },
});

In xx3 build.zig:

const xx2_module = b.dependency("xx2", .{}).module("xx2");
exe.root_module.addImport("xx2", xx2_module);
3 Likes

Thanks :pray:, it worked the way you did

1 Like