4 ms·
I'm curious about why they didn't statically link SDL2 in. It wasn't an option with SDL1.2 due to licensing, but SDL2 explicitly allows it.
by FreeFull 5y ago
I'm curious about why they didn't statically link SDL2 in. It wasn't an option with SDL1.2 due to licensing, but SDL2 explicitly allows it.
- AnIdiotOnTheNet 5y agoSDL2 will even allow the user to override the static library and substitute their dynamic copy at runtime, so even though you distribute it statically you don't lose out on the advantages of updates. ...why don't all libraries work that way?
- badsectoracula 5y agoYou can override a bundled dynamic library so aside from having a single file when you link statically there isn't much of a practical use for it from the user's perspective and from the library developer's perspective it is a PITA (SDL2 does a lot of manual symbol juggling).
- badsectoracula 5y agoThis is not a good idea because SDL can get fixes down the line to be more compatible with changes in desktops. I have a bunch of very old games on Linux using SDL 1.2 and whenever they bundled their own version pretty much never works, but i can easily fix that by deleting it and letting the game use the system provided one. And TBH i'd rather games just assume SDL or is available and have it part of the system requirements (they already have other software requirements anyway), perhaps with a tiny launcher that tries to load the library dynamically and if fails it reports a more user friendly error. Most gamers on Linux will have it installed anyway since they'd be either launching from Steam (which bundles it as part of its own runtime) or also have other games installed. (sadly SDL2 breaking ABI backward compatibility with SDL1 puts a wrench to that idea, which is why personally instead of using SDL2 i just write my own code - e.g. SDL2 fullscreen mode doesn't work in many window managers)
- MayeulC 5y agoLike the sibling comment points out, you can easily load your own by setting an env var: SDL_DYNAMIC_API=/my/actual/libSDL-2.0.so.0 ./MyGameThatIsStaticallyLinkedToSDL2 https://github.com/libsdl-org/SDL/blob/main/docs/README-dynapi.md https://github.com/libsdl-org/SDL/blob/main/docs/README-dyna...
- badsectoracula 5y agoYes i know about this (mentioned it in another reply) but this assumes there weren't any changes (like another dev made here) and really there isn't much of a reason to do that when you can just bundle the library with your binary or, even better, just rely on it being there and have it as part of your system requirements.
- frankohn 5y agoI agree, for their use case they should have linked to SDL2 as a static library. It was the best option instead of patching the binary with patchelf. I think many developers don't know about static libraries. For some reason they think they have to use a shared libraries. This is probably due to many tutorial saying something like: download the SDL2 library from there, it is provided as a shared library, here the instructions to use it with Visual Studio. The way I do is with static libraries, I ship a single executable, all the third-party libraries are linked in as static libraries. The only dynamic libraries the exectuable will use are the standard libraries that are part of the OS. I do this very easily with the help for lhelper: https://github.com/franko/lhelper https://github.com/franko/lhelper (I am the author) that has recipes to build many libraries including SDL2. It builds the library on you system using your compiler and your settings. By default it will build static libraries so you don't have to bother distributing additional dynamic libraries.
- wheybags 5y agoWe did this when I worked on factorio (on all three desktop platforms, not just linux), it works really well. Side bonus is you can make the inevitably required small tweaks inside the library easily because it's all integrated in the same build system as the rest of your game.
- MayeulC 5y ago> you can make the inevitably required small tweaks inside the library How do you handle Steam or the user updating SDL2 to a newer version, then (see the sibling comments about dynapi)? Does your game depend on those tricks to run?
- wheybags 5y agoWe statically linked it, and didn't use the system/steam provided version at all. I guess if a user tried to use SDL_DYNAMIC_API, it would break in strange and unexpected ways. TBH I didn't know that option existed until just now. We never had any problems with our approach, afaik.