#Use C Library that uses Cmake in Zig project

1 messages · Page 1 of 1 (latest)

lofty vault
#

I want to use a c library, in this case GLFW in my zig project.
I imported the main headerfile into my src/main.zig file like this ```js
const glfw = @cImport(
@cInclude("../lib/glfw/include/glfw3.h")
);

but i think i also have to do some setup in my build.zig file to use a library that uses cmake and I dont have any Idea how to do that. And I wasn't able to find some good examples online...
vapid egret
#

In build.zig add .addIncludePath(.{.path = "glfw-path/include" }); and @cInclude add header only (no absolute path).
To find out if it worked, cimport.zig will be generated in the zig-cache or see error not found.

#
const glfw = @cImport({
// multi headers
    @cInclude("stdio.h"); // zig/lib/include path
    @cInclude("glfw3.h"); // custom or system path
});