I'm trying to get back into programming with OCaml after a long time of not using it, and since I don't have Linux on my current computer, I've been trying to do it through WSL (Windows Subsystem for Linux).
After doing everything as I would have in Linux, whenever I try to compile a piece of code using the Graphics module, I get the following outcomes:
- If I try to use the
open_graph
command, I get the following error:
Exception: Graphics.Graphic_failure "Cannot open display ".
I get that exact error if the argument of open_graph
is an empty string, or starts with a space. If the string argument is not empty and doesn't start with a space (which, from what I've read, shouldn't be used anyway), the error message includes said argument as follows:
Exception: Graphics.Graphic_failure "Cannot open display [argument of open_graph]".
- If the code only uses base OCaml commands and Graphics commands that doesn't require an open graph (like rgb), everything compiles normally.
I found this thread where users raised the question of the DISPLAY variable possibly being "wrong". The original poster of said thread has a different issue, but I felt it is relevant, as I was thinking that perhaps using WSL could have made my DISPLAY variable "off", or could require me to use a different value for DISPLAY than I would use on a complete Linux OS - but, to be perfectly honest, I have no idea what that would be.
I tried my best to understand everything I read and to explain my issue clearly, but I only have moderate experience with Linux and programming in general, so I'm sorry if I misunderstood something or if my explanations weren't the clearest. In that case, please let me know, and I will try my best to rectify it.
Cheers!
Example of complete code and exact error message:
#use "topfind";; #require "graphics";; Graphics.open_graph "";;
Error message returned:
Exception: Graphics.Graphic_failure "Cannot open display ".