#how to import file
1 messages · Page 1 of 1 (latest)
addIncludePath is for c headers. you cant import zig files that are higher up than your root file (the file with fn main in it)
you could make it into a module and import that
what is the fucntion ?
exe.root_module.addAnonymousImport("shared", .{ .root_source_file = b.path("…") });
then in your exe its @import("shared");
although that will mean you will have to import shared.zig as shared everywhere else you import it
yh thats fine i guess
although it looks like shared is in your src directory, is there a reason its higher up than your root?
no reason but my src contains my server/client/shared directory
and files
its to make it organised haha
error: unable to check cache: stat file 'src/shared' failed: IsDir
ah i gotcha, yeah thatd be a good use of a module to share between the two. youd probably want something like this then:
const shared = b.createModule(.{
.root_source_file = b.path("src/shared/shared.zig"),
});
exe_client.root_module.addImport("shared", shared);
exe_server.root_module.addImport("shared", shared);
deleting your cache sometimes gets rid of that :P
or make sure youre putting shared.zig as the root source file and not the directory. idk if thatd cause that error tho just tested it, that happens when you put a directory as your root_source_file
and then import with jsut @import("shared");?
yep, that should work