I’m want to write shared library to try zig in a new case. There’re nothing easier then building shared library, but I can’t figure out, how to emit headers in build.zig. While I’m calling lib.getEmittedH, it’s just crushing the build…
Also, haven’t found any information about emiting C-like structs.
I use zig 0.14, and 0.13 gave the same result.
I always have an option to write header myself, but I think creating proper headers from zig build would be much better solution.
P.S I’m testing building with the example library that being created by zig init.
I’ve found nothing…
I’ve written header file by hand for my task. It’s not a solution, but in this case I think it’s faster to do it by hand, then trying to fix.
Since even -femit-h doesn’t work (I didn’t managed to make it work), I think in current release it’s not possible…
Edit: If you will manage to fix it for your build, I’d like to see that. May be I’m doing something wrong…
Currently, there are an issue opened on github.
It’s assigned to 0.15.0 milestone, but it can be reassigned to later versions, as it’s not priority feature (from my understanding).
Damn, I wanted to use Zig as a bridge between C libraries and Rust, but it’s getting in the way.
I’ll have to write the .h file manually so Rust’s bindgen can consume it.
Just voicing my support for prioritizing this functionality.
Writing the header by isn’t the worst problem in the world for some small wrappers, but it is slightly disappointing to not have it available. That’s not intended to be a dig or a slight, either – I totally understand that this is the risk of using an in-development language. But, hoping some progress can be made on this! Writing Zig code to interface directly with other C/C++ libraries is a really powerful and compelling use case.
The compiler is indeed telling me that this feature is broken:
λ zig build
install
└─ install mylib
└─ compile lib mylib Debug native failure
error: error: -femit-h is currently broken, see https://github.com/ziglang/zig/issues/9698
I’d like to give a +1 on this feature.
IMO, the argument “if you develop it in zig, you can use it in C & C++” is pretty impactful to convince people on adopting the language !