Help add c include path

Hi all!
Very new to ZiG,
trying to import c header that is located in standard /usr/include, but doing something like

const stuff = @cImport({
    @cInclude("mystuff.h");
});

yields error: 'mystuff.h' file not found

i’ve googled around and found a simple solution - to add to build.zig something like exe.addIncludeDir("/usr/include");
while it itself looks like a hack - I cannot even find addIncludeDir function in zig 0.11, and cannot find any release notes about it…

can please someone help me with this tiny thing?

Hi @hex, welcome to ziggit.

The function is called addIncludePath
Usage is: exe.addIncludePath(b.path("/path/to/include"));

1 Like

Oh thank you!
By the way, is this the best way to do it? Sounds like including standard locations like /usr/include may be done with some special flag/option/function, no?

1 Like

I don’t know. I am guessing, that zig does not include the system includes because it bundles c libraries like musl, gnu and mingw.

In Zig 0.12.0, you have to now add the include path for @cInclude() to the Zig module in question (using std.Build.Module.addIncludePath). std.Build.Step.Compile.addIncludePath appears to be applicable only to C files added using addCSourceFile(s).

Just in case anyone runs into this. I was banging my head wondering why the compiler just isn’t finding the stupid file :stuck_out_tongue:

1 Like