cImport and absolute paths

I’ve only seen examples of @cImport with either global includes or absolute paths. It may just be my system, but I couldn’t get relative paths to get picked up. If need be, I can generate them, it just seems like I’m missing something if not?

I checked the docs but I can’t see anything that enables this: Documentation - The Zig Programming Language

Part of the reason I’m asking is that I’m requiring the user to provide a symlink to a folder to avoid a myriad of issues with specifying path variables between systems by importing from local c-files that are not in the apart of the global includes. That way, I can control the include paths top-to bottom regardless of how the user has their system setup externally. Any examples that anyone knows of?

I went ahead and generated them, so the issue is solved… but I’d like to leave this open if anyone has more information.

I believe that this line explains the situation:

-I: Specify a search directory for include files. May be used multiple times. Equivalent to clang’s -I flag. The current directory is not included by default; use -I. to include it.

Zig only has an equivalent for #include <...>, not #include "..." (see here). So the only option is to add the project root directory (and/or other relative directories) to the search path via -I or the equivalent in build.zig. I assume that the motivation behind this is that there is supposed to only be one @cImport per project, and thus relative paths are kind of redundant with -I.

3 Likes

Interesting - thanks for the info. Command line flags are not quite what I had in mind, but that certainly explains why it doesn’t pick up relative paths.