The Zig compiler hangs when doing a double @cInclude of the same C header. This also persists when doing these @cIncludes across different Zig source files (which is how I encountered the bug in the first place). This behavior was only tested on Windows.
Most minimal reproducible example of this:
const first = @cImport({ @cInclude("time.h"); });
const second = @cImport({ @cInclude("time.h"); });
pub fn main() void {
_ = first.time(null);
_ = second.time(null);
}
Saved the code into main.zig and ran zig build-exe main.zig -lc. The compilation never seems to finish.
If one needs to use the same @cInclude in two separate .zig files, the workaround for now is to make the one include pub: pub const c_time = @cImport({ @cInclude("time.h"); });, and refer it in the second file: const c_time = @import("first_file.zig").c_time;.
This is a bug but note that duplicate import of the same C header file is almost certainly not what you want. @cImport docs
Most helpful comment
If one needs to use the same
@cIncludein two separate.zigfiles, the workaround for now is to make the one includepub:pub const c_time = @cImport({ @cInclude("time.h"); });, and refer it in the second file:const c_time = @import("first_file.zig").c_time;.