How best to link to SDL2

I’m currently linking to SDL2 simply by having libsdl2-dev as a build-packages dependency.

I though this was working but a recent test found a machine where I get the following error.

Failed loading libGL.so.1: libGL.so.1: cannot open shared object file: No such file or directory

SDL will be doing dlopen tricks which is normal for libGL, the system does have a libGL which is found by my non snap build.

My question is am I doing something wrong, it feels like SDL2 is big and complicated enough that it should be a snap itself that other snaps can require (is this how snaps work?) at the moment I’m getting 2.0.4 from the libsdl2-dev dependency which is about two years out of date so that would be another reason to snap it.

How should I be linking to SDL2 as a dependency in a snap build?

You should just need to stage the necessary package SDL2 is looking for.

stage-packages:
  - libglu1-mesa

This should be sufficient to pull in the necessary libGL (and others) that SDL2 needs.

Thanks, That helps, although it now hangs needing other libs: i965_dri.so , then trying swrast_dri.so and failing again, then hanging.

I guess my main concern here is why is this snap working on one machine and failing on another?

I’ve tried to find any obvious difference and their systems seem identical in terms of versions of snapd and the snaps installed.

you also want to add libgl1-mesa-dri to your stage-packages (and makes sure its content ends up in your library search path of the app)

At my end, this works properly with the LD_LIBRARY_PATH set by desktop-launch script from snapcraft-desktop-helpers

+      # Accelerated Renderer support for libSDL2
+      - libglu1-mesa
+      - libgl1-mesa-dri
+