Can't find SDL3 headers, Issue building my C project with Zig's build system

I am developing a game engine + game in C and I’ve wanted to integrate the Zig build system so that I can have easily reproducible builds and static cross-platform dependencies and I’ve gotta say my experience has been excellent so far, except that I’ve come across this issue where, even though SDL3 is accessible to me through Zig (as I am using the wrapper by gota7 so that I can begin porting parts of my engine to Zig), the headers don’t seem to be accessible to the C files themselves.

Here’s the source code, I apologize for the mess, I abandoned this sloppily made game jam game a while ago and just recently retook the project: nelson/socks/src/branch/main

You probably need to call exe.root_module.addIncludePath(b.path("src\SDL3")) or whatever the equivalent would be for your build.

Would “b” here be the SDL Wrapper dependency itself? wouldn’t that point to the wrapper’s files instead of the actual SDL library?

“b” is the *std.Build pointer that gets passed into your build function automatically.
b.path() is a shorthand for creating a structure called std.Build.LazyPath, which is (usually used as) a path relative to the CWD of the build process and is slightly more robust than using string literals as paths.

yeah but wouldn’t that require me to have the SDL headers on my repository instead of getting them from the SDL library i’m already including in my build.zig.zon file?

Yeah.
There are ways around it.
There’s a good library you can import as a dependency (GitHub - castholm/SDL: SDL ported to the Zig build system) which sidesteps all of this.
Failing that, you can try using the std.Build.Dependency.path() function to get a path relative to the dependency root - that way you should be able to add an include path without having to merge the dependencie’s file into your project.

i mean… i already do that, it’s imported by the wrapper library i am using, that’s why i am asking how could i get zig to import whatever that library is exporting

an idea i am having right now would be to somehow get a dependency instance’s dependency instance and get the lazypath from that… hmm

Somewhat fixed it here: nelson/socks/src/commit/66b7950973f9829e1c1f6000f78c3e1fd0b24d69/build.zig

it’s not perfect, maybe someone here will be able to tell me a better way to do this but hey, this’ll do for now :slight_smile:

thanks @tholmes for the idea!

1 Like

To be fair I would probably do it like this.

1 Like

@darltrash is it necessary to take a wrapper for SDL3? Zig build system allowed me to go without any binding. In my project, I set SDL3 itself as dependency in build.zig.zon and called the CMake from the Zig build script. The link if you are curious

1 Like