From what I have read I think you want to use a static library that may be compiled separately / by someone else, is that the case?
I think you still at least need a header file that contains declarations of the functions you want to use. You would use that header file with @cImport()
to make zig aware of the available functions.
Then you could try adding your libdemo.a
via exe.addObjectFile("path/to/libdemo.a");
like you wrote.
However I also think that your libdemo.a
needs to be built so that all functions that you want to use from zig are declared with extern
.
In your executable you would have:
const demo = @import("demo.zig");
demo.zig:
pub usingnamespace @cImport({
// should be accessible from a path added via exe.addIncludePath
// or use absolute path
@cInclude("demo.h");
});
I havenât tried something like this with zig yet, so there could be things I am missing here.
Take a look at @import.
"std"
is special and always available (probably (I guess) It gets compiled into the zig executable, which would explain why you renaming files doesnât have any effect).
If you want to include something other than those special things provided by zig, you have to use a path to an actual file, which is why your imports also need to mention the file extension .zig
not just demo
.
(Didnât see that you had a package path defined, but I am still confused, do you want to build a static library, or use one or both?
I think maybe sepparating it into two experiments one about building a library, one about using one may make things easier.
Also consider publishing a repo with your test setup, that way it would be easier to see all the details of what your test does and maybe see some detail that isnât right. I am too lazy to try to reverse engineer your setup 1:1 from your commentsâŚ)
As far as I can tell builder.addStaticLibrary
is for building a static library not for adding the static library to your exe build. And in theory exe.addObject
should work to get the implementation part of your built static library into your exe build step, but you still need to add the interface info via the header file.
Hope that helps, so far I havenât done a lot of experiments in that area of using zig, so I am not 100% sure.