#Include C Code in Package Module
1 messages · Page 1 of 1 (latest)
I am trying this:
const expat = b.addModule("expat", .{
.root_source_file = .{ .path = "src/root.zig" },
.target = target,
.optimize = optimize,
.link_libc = true,
});
expat.addCSourceFile(.{
.file = .{ .path = "libexpat/expat/lib/expat.h" },
.flags = &.{"-std=c99"},
});
but, it can't find the headers when I try to include them
const bindings = @cImport({
@cInclude("expat.h");
});
Include C Code in Package Module
C:\dev\expat-zig\zig-cache\o\c373578ee098d1b8f40047ead2cf5ee4\cimport.h:1:10: error: 'libexpat/expat/lib/expat.h' file not found
Do not compile header files, here you just need expat.addIncludePath(.{ .path = "libexpat/expat/lib" }); on Zig master
Thank you, how do I access the header file members in the Zig file, then?
bindings.member
ah, thanks that works now. I had to add the include and libc to the test runner:
const lib_unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/root.zig" },
.target = target,
.optimize = optimize,
});
lib_unit_tests.linkLibC();
lib_unit_tests.addIncludePath(.{
.path = "libexpat/expat/lib",
});
Is duplicating this code the correct solution?
I'd expect that to not be necessary with a Zig compiler version from this week (should just need linkLibC + addIncludePath on the module) but for older Zig versions that looks correct.
hmm, I don't think that the module and the test are connected in the dependency tree, though