#Zig as build system for C/C++: how to link other libraries?

1 messages · Page 1 of 1 (latest)

odd lion
#

I recently discovered that raylib provides a build.zig which allows to build that C project using Zig’s built-in C compiler. I then wanted to take this as an opportunity to explore this a little further and thereby gain a better understanding of it.

So my plan is to write a small C++ application with raylib as the only dependency. But for the first time not using CMake and g++ but Zig (current master aka 0.14.X) as the build system and compiler.

So I set up my project using zig init and then replaced the zig sources with my main.cpp according to the documentation I found on how to declare a C++ executable.

Then I added raylib as dependency to my build.zig.zon using zig fetch.

At this point I’m stuck. How do I actually import raylib as module from my dependencies, link it to my executable and make sure to add its includes?

Are there some additional requirements to raylib’s build.zig [1] to be able to do so, e.g. an explicit module export statement? And if yes, is that requirement fulfilled?

[1] https://raw.githubusercontent.com/raysan5/raylib/refs/heads/master/build.zig

woeful flare
#

raylib's build.zig is set up to build a library and makes headers available at dep.path("src"). so you need to add that path to your include path and link the library and you should be golden. there is no module in this case as it's not exporting any zig interface

#

you can do this by retrieving the raylib library artifact from the dependency and using exe.addIncludePath