(SDL2 bindings for OCaml with runtime dynamic loading)
original: https://github.com/dbuenzli/tsdl
opam pin https://github.com/sanette/tsdl.git
opam install tsdl.1.2.0-a2386d5.dune
opam unpin https://github.com/sanette/tsdl.git
-
This version has been reported to work on Windows-Cygwin (see below) (and of course in Linux and Macos too).
-
It works with any version of SDL >= 2.0.7. (Of course, if you have a more recent version, more functions will be available)
-
As far as I understand, SDL+Windows has some peculiarities that make the use of
pkg-configfor finding C-compile flags inappropriate. In particular, a problem arises because of the way theMainentry point is handled. In principle, you may decide (or not) that SDL takes care of your Main function, so that it can inject OS specific code (for Windows). In this case, you should link withSDL2mainand use the-mwindowsto tell Windows to use a specific GUI startup. (This is what pkg-config suggests.)However, most SDL bindings to other languages (
tsdlfor OCaml, but also, apparently, bindings for Rust, Zig, Python, Lua) decided not to rely on this and instead callSDL_SetMainReadyat init, to tell SDL "we keep ourmainentry point". In this case, Windows should not add its GUI startup, so one should not link withSDL2main, nor use the-mwindows. Instead, the-mconsoleflag would be more appropriate.=> In this version, I have removed the call to
pkg-config. The library uses runtime dynamic loading to access the SDL2 library. The SDL2 shared library is not linked at build time; instead it is located and loaded at runtime usingdlopen(or the platform equivalent). -
Another Windows specificity: the "function"
SDL_RWclose, which on Linux/MacOS can be bound (bytsdl) via a foreign call, is just a Macro in the Windows version. Hence the foreign call is not recognized, and compilation fails with
Fatal error: exception
Dl.DL_error("dlsym: The specified procedure could not be found.")
=> In this version SDL_RWclose is implemented in OCaml by
accessing the rw_ops_close entry of the rw_ops structure.
Thanks @digitallysane for his patience with numerous tests! sanette/tsdl-ttf#9