Unfortunately this package relies on system libraries so you won’t be able to use it to cross compile your application.
(unless there is some way to do the build without the system libraries or supply the needed parts, I am not entirely sure, for pure dynamic libraries it may work, but if there are also headers needed at build time it would probably fail)
I haven’t used this package in particular, but usually you start with adding it as a dependency to your project with:
zig fetch --save git+https://github.com/allyourcodebase/SDL
which fetches the dependency and adds this to your build.zig.zon
(commit/hash may differ once the branch has been updated):
.SDL = .{
.url = "git+https://github.com/allyourcodebase/SDL#a13d7e80e8d847db2b2ff8f334d57eb5bbb489dd",
.hash = "12200aa79b05aaeefff144b9e376371e2e7ddc982b9207d146163baf56361331a834",
},
Then you can add the dependency in your build.zig
:
const sdl_dep = b.dependency("SDL", .{
.target = target,
.optimize = optimize,
});
const sdl_lib_artifact = sdl_dep.artifact("SDL2");
exe.linkLibrary(sdl_lib_artifact);
On linux I get with that:
SDL_opengles.h:33:10: error: 'GLES/gl.h' file not found
So maybe it relies on system headers for that.
I just saw that the build.zig
uses linkSystemLibrary for window / mac etc., so that won’t work may not unless you compile on windows. (not sure)
I think (but I am not sure that) if you want cross compile to work you would have do a lot of work on the SDL2 library to make it support cross compile (remove/bundle all the system dependencies), would probably be way easier to get different compiled libraries like @tsdtas has suggested.
Alternatively you could port your application to use SDL3 and this project:
Which states that it supports cross compile.