ocaml / graphics

The Graphics library from OCaml, in a standalone repository
Other
56 stars 29 forks source link

Cannot load graphics library on ARM macOS #33

Closed kevinbioj closed 3 years ago

kevinbioj commented 3 years ago

Hey!

I've been trying to play with OCaml on ARM-based macOS, but I've been facing an issue which can be problematic for my usage. Everything works fine, except for the graphics library which completely refuse to load up. OCaml runs on version 4.12.0 freshly installed from opam, packages core and graphics were added too to bring up graphics functionnality.

I use OCaml's top find in order to get my libraries loaded, here is a sample code:

#use "topfind";;
#require "graphics";;

While this code works on my native Linux (Debian) system, and my Debian on Windows 10 through WSL2... it does not work here.

# #require "Graphics";;
/Users/kevin/.opam/default/lib/Graphics: added to search path
/Users/kevin/.opam/default/lib/Graphics/graphics.cma: loaded
Cannot load required shared library dllgraphics_stubs.
Reason: /Users/kevin/.opam/default/lib/stublibs/dllgraphics_stubs.so: dlopen(/Users/kevin/.opam/default/lib/stublibs/dllgraphics_stubs.so, 10): Symbol not found: _XAllocColor
  Referenced from: /Users/kevin/.opam/default/lib/stublibs/dllgraphics_stubs.so
  Expected in: flat namespace
 in /Users/kevin/.opam/default/lib/stublibs/dllgraphics_stubs.so.

I do get this weird error, apparently a library isn't providing what it should which leads OCaml to fail up loading it... but I can't find anything related when searching on Google. Side note, I haven't got any error or warning then opam was installing OCaml, core and graphics packages - aside from the classic pkg-config I had to install on all my systems anyway.

I'm using a late-2020 MacBook Air with an M1 chip, on macOS Big Sur 11.2.2. I'm up to you if you need any more information or debug files.

Thanks!

xavierleroy commented 3 years ago

Shooting in the dark here:

The Graphics library uses the Xlib API for drawing things. On macOS, the Xlib API is implemented by the xquartz package provided by Homebrew.

Are you sure your xquartz library is an ARM binary? could it be an x86-64 binary? It all depends on which version of Homebrew is installed on your machine.

Also, you could try to trace the dynamic loading process using these tricks: https://craftware.xyz/tips/Dynamic-libraries-loading.html

kevinbioj commented 3 years ago

Looks like you were right 👀 My XQuartz installation was indeed an x86 build according to macOS's activity monitor. Hopefully, there was an update (2.8.0_rc2) and it looks like it's now running natively. After that I've reinstalled the graphics library, now everything works fine! Thanks.