Cannot build SDL examples <- Cannot build SDL from Zig build source
When I try to run zig build sdl-ontop or zig build sdl-standalone, I see the following error:
❯ zig build sdl-standalone
sdl-standalone
└─ run sdl-standalone
└─ compile-sdl-standalone
└─ install sdl-standalone
└─ zig build-exe sdl-standalone Debug native
└─ zig build-lib SDL2 Debug native 1 errors
/home/user/.cache/zig/p/1220bdd8cfd7740aa9f8cce7679824a17b364ff5a34698aa2c1c75ea77e0df15a3b1/include/SDL_opengles.h:33:10: error: 'GLES/gl.h' file not found
#include <GLES/gl.h>
^~~~~~~~~~~~
/home/user/.cache/zig/p/1220bdd8cfd7740aa9f8cce7679824a17b364ff5a34698aa2c1c75ea77e0df15a3b1/src/render/opengles/SDL_render_gles.c:27:10: note: in file included from /home/user/.cache/zig/p/1220bdd8cfd7740aa9f8cce7679824a17b364ff5a34698aa2c1c75ea77e0df15a3b1/src/render/opengles/SDL_render_gles.c:27:
#include "SDL_opengles.h"
Here are my headers.
❯ ls /usr/include/G
…include/GL/ …include/GLES2/ …include/GLFW/
…include/Glacier2/ …include/GLES3/ …include/GraphicsMagick/
I don't have GLES/gl.h.
This works: zig build sdl-standalone -fsys=sdl2.
This was discussed extensively here https://github.com/david-vanderson/dvui/issues/117
It seems to be an allyourcodebase/sdl issue building on linux
Recently we started compiling SDL on linux by default. Before we always assumed SDL was already installed (same as passing -fsys=sdl2 now).
I haven't looked into this very much. I suspect one of 2 things is happening:
- Standard SDL wouldn't compile anyway due to the missing header, or
- Standard SDL configure would figure out which of the headers you do have it could use, and tweak some compilation options. If that is the case, then https://github.com/allyourcodebase/SDL needs those smarts added to its build.zig
Probably 2. The official build system is CMake. Here it links GLESv2.
I have successfully built https://github.com/libsdl-org/SDL. (The WIP SDL 3.0)
Seems like https://github.com/allyourcodebase/SDL is not accepting issues. Maybe we revert to the behavior of always using the system SDL on Linux for the meantime. I doubt that allyourcodebase/SDL will have all the smarts the official SDL build system has.
The best solution here would be for us to figure out what needed to be added to the https://github.com/allyourcodebase/SDL build.zig and send a PR. In the future we'd like to not depend on any libraries being installed already (of course we must be practical about this).
Let me see if I can reproduce this, because then I can work on a PR. Thanks very much for the link to the CMake part!
I pushed a commit to disable SDL trying to build support for opengles1 - @iacore does this fix it for you?
Note that I had to wipe my ~/.cache/zig folder to get zig to recompile SDL.
I confirm this fixes the issue. Thanks!