How to emit headers file from build.zig. zig 0.14.0

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.

Emitting headers is still broken.
See: How to enable build.zig also emit header file? - #6 by castholm

I’m using this code:

...
    const lib = b.addSharedLibrary(.{
        .name = "breakdown",
        .root_source_file = b.path("src/root.zig"),
        .target = target,
        .optimize = optimize,
    });

    const installed_lib = b.addInstallArtifact(lib, .{});
    installed_lib.emitted_h = lib.getEmittedH();
    b.getInstallStep().dependOn(&installed_lib.step);
...

It just throws
error: the following build command failed with exit code 1

May be -femit-h have been broken again. Because calling zig build-lib -femit-h .\src\root.zig in the shell produces no files.

Also, tried to change to the zig version to 0.13.0, and there no files were emitted.

any progress? i can’t figure this out either

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…

1 Like

emit-h is broken. It’s Zig, not you.

1 Like