fccm / OCamlSDL2

OCaml interface to SDL 2.0 (for Linux, Windows, MacOS, and ChromeBook)
Other
51 stars 10 forks source link

Support OCaml 4.07.1 #12

Open xyproto opened 5 years ago

xyproto commented 5 years ago

OCamlSDL2 no longer builds with the latest version of OCaml+SDL2.

I get the following error:

sdltimer_stub.c: In function ‘caml_SDL_GetTicks_d’:
/usr/lib/ocaml/caml/memory.h:335:12: error: ‘caml__frame’ undeclared (first use in this function); did you mean ‘caml_raise’?
     (void) caml__frame, \
            ^~~~~~~~~~~
/usr/lib/ocaml/caml/memory.h:416:3: note: in expansion of macro ‘CAMLxparam1’
   CAMLxparam1 (x)
   ^~~~~~~~~~~
sdltimer_stub.c:29:5: note: in expansion of macro ‘CAMLlocal1’
     CAMLlocal1(ret);
     ^~~~~~~~~~
/usr/lib/ocaml/caml/memory.h:335:12: note: each undeclared identifier is reported only once for each function it appears in
     (void) caml__frame, \
            ^~~~~~~~~~~
/usr/lib/ocaml/caml/memory.h:416:3: note: in expansion of macro ‘CAMLxparam1’
   CAMLxparam1 (x)
   ^~~~~~~~~~~
sdltimer_stub.c:29:5: note: in expansion of macro ‘CAMLlocal1’
     CAMLlocal1(ret);
     ^~~~~~~~~~
fccm commented 5 years ago

could you try this: https://github.com/pelzlpj/orpie/issues/10 to see if it fixes the error or not?

xyproto commented 5 years ago

Now I get a completely different set of errors.

Please try running make in a directory with these files: https://github.com/xyproto/sdl2-examples/tree/master/ocaml

fccm commented 5 years ago

I tried your sample, it works just fine on my computer (I'm using OCaml 4.07.1 and SDL 2.0.9)

Which versions are you using? What are the errors?

xyproto commented 5 years ago

I'm also using OCaml 4.07.1 and SDL 2.0.9, but on 64-bit Arch Linux.

Perhaps there is something wrong with the Makefile I'm using.

The errors look like this:

[main] Compiling.../usr/bin/ld: OCamlSDL2/src/libsdl2_stubs.a(sdlinit_stub.o): in function `caml_SDL_Init':
/home/afr/clones/sdl2-examples/ocaml/OCamlSDL2/src/sdlinit_stub.c:55: undefined reference to `SDL_Init'

Attaching full output. output.txt

fccm commented 5 years ago

It look like the linking of SDL2 was not correct. In your log file output.txt we don't see how it was compiled. Maybe the script prm.ml does something wrong. Maybe you could try to provide the correct values to make with the variable LIBS based on the output of sdl2-config --static-libs on my computer the output is: -L/usr/lib -lSDL2 -Wl,--no-undefined -lm -ldl -lpthread -lrt and ocaml prm.ml $(sdl2-config --static-libs) outputs: -L/usr/lib -lSDL2 -lm -ldl -lpthread -lrt

xyproto commented 5 years ago

Hi and sorry for the late response. I'll include as much output and details as possible.

Here is the Makefile I am using: https://github.com/xyproto/sdl2-examples/blob/master/ocaml/Makefile

And the script for cloning and patching OCamlSDL2 (I get the same error message with or without using these lines of sed): https://github.com/xyproto/sdl2-examples/blob/master/ocaml/clone.sh

The output of sdl2-config --static-libs on my system just gives this output:

Usage: /usr/bin/sdl2-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]

The output of ocaml prm.ml $(sdl2-config --static-libs) if I enter sdl2-examples/ocaml/OCamlSDL2/src is:

Usage: /usr/bin/sdl2-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]

Every library on Arch Linux are installed as dynamic libraries.

fccm commented 5 years ago

OK, then the error is quite clear :) there is no --static-libs option for sdl2-config So you should replace it by sdl2-config --libs and then it should work just fine!

(I made the choice to use static libs because it makes it more easy to distribute binaries, and I thought maybe someone will want to produce binaries for some game jam or other. Several years ago I was a packager for mageia, and I pushed a little to provide also static libraries in addition to dynamic ones for this reason, also we can find old binaries on the internet of some kind of small games with binaries that don't work anymore because these binaries expect old versions of dynamic libs, this is why it's better to distribute binaries compiled with static libs if we want more people can use it and for longer time)

The links you provide are broken but I was able to find it browsing your project on github. In "ocaml/clone.sh" you fix things that I fixed recently so you don't need it anymore.

I also recently provided ocamlsdl2 to opam: https://opam.ocaml.org/packages/ocamlsdl2/ I provided to versions of ocamlsdl2: 0.02 and 0.03 0.03 fits well for the last version of SDL2: 2.0.9 0.02 fits well for an older version of the SDL2: 2.0.6 If you want to tell your users you can tell them to install 0.02 or 0.03 depending on which SDL2 they are using. (Also you should know that Tsdl is fine for SDL2 2.0.6 but not for the last one 2.0.9) Maybe in your ocaml directory you could provide 2 different subdirectories: one for ocamlsdl2 and one for tsdl to make everyone happy :)