#how to import file

1 messages · Page 1 of 1 (latest)

candid tangle
#

how to import file

thorny tiger
#

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

candid tangle
#

what is the fucntion ?

thorny tiger
#
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

candid tangle
#

yh thats fine i guess

thorny tiger
#

although it looks like shared is in your src directory, is there a reason its higher up than your root?

candid tangle
#

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

thorny tiger
thorny tiger
#

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

candid tangle
#

and then import with jsut @import("shared");?

thorny tiger
#

yep, that should work