Exporting a .h file from a zig module?

I’m trying to package up minimal set of libc functions I find useful when working with C code in Zig freestanding systems but I’m having problems with include paths.

My module has a header file with function prototypes which I need to export.

In the module’s tree I can successfully build a sample:

git clone https://github.com/ringtailsoftware/zeptolibc.git
zig build helloworld

I’m now trying to move this example out to its own repo and pull in the module as a dependency

git clone https://github.com/ringtailsoftware/zeptolibc-example.git
zig build

But it can’t find the header,

error: 'zeptolibc.h' file not found
#include "zeptolibc.h"

I can see the include path for the module and it does contain zeptolibc.h, so I’m not sure why it’s not being picked up?

/opt/homebrew/Cellar/zig/0.13.0/bin/zig build-exe -ODebug -I /Users/trj/Desktop/org/zig/git/zeptolibc-example/src --dep zeptolibc -Mroot=/Users/trj/Desktop/org/zig/git/zeptolibc-example/src/main.zig -cflags -Wall -- /Users/trj/.cache/zig/p/12202d3462b83947191fee3c5953d77bad5e9427f9e3dd05e09b2bee54e2edae98f2/src/printf.c -I /Users/trj/.cache/zig/p/12202d3462b83947191fee3c5953d77bad5e9427f9e3dd05e09b2bee54e2edae98f2/src -Mzeptolibc=/Users/trj/.cache/zig/p/12202d3462b83947191fee3c5953d77bad5e9427f9e3dd05e09b2bee54e2edae98f2/src/main.zig --cache-dir /Users/trj/Desktop/org/zig/git/zeptolibc-example/.zig-cache --global-cache-dir /Users/trj/.cache/zig --name zeptolibc-example --listen=-

ls /Users/trj/.cache/zig/p/12202d3462b83947191fee3c5953d77bad5e9427f9e3dd05e09b2bee54e2edae98f2/src
main.zig    printf.c    zeptolibc.h

That looks like the modules include path is incorrect. I pulled your example repo and added the following to build.zig:

exe.addIncludePath(zeptolibc_dep.path("src/"));

After that it should build fine.

Someone might know a better way to add the include paths.

1 Like

Aha, thank you!