I am using nix-shell to pull in glfw and wrote this small C program to test that everything is ok:
#include <GLFW/glfw3.h>
#include <stdio.h>
int main() {
if (!glfwInit()) {
printf("Failed to initialize GLFW\n");
return -1;
}
printf("GLFW initialized successfully!\n");
printf("GLFW version: %s\n", glfwGetVersionString());
glfwTerminate();
return 0;
}
I can compile it with clang -o test main.c $(pkg-config --cflags --libs glfw3)
and everything seems to work ok.
Now I am trying to do the same in zig while using translate-c.
The first step I did:
zig translate-c $(pkg-config --cflags --libs glfw3) src/c.h > src/c.zig
And that seems to nicely create my c.zig
file for me.
The next step would be to make this part of build.zig
but I don’t know how add glfw3
include paths, ideally using pkg-config:
const c_translate = b.addTranslateC(.{
.link_libc = true,
.target = target,
.optimize = optimize,
.root_source_file = b.addWriteFiles().add("c.h",
\\#include <GLFW/glfw3.h>
),
});
// How to add glfw3 include path using pkg-config?
exe_mod.addImport("c", c_translate.createModule());