1

The last line of this code

#load "graphics.cma";;
open Graphics;;
open_graph " 600x400";;

returns the following error:

Graphics.Graphic_failure "Cannot open display My-Machine.local"


Since I use Emacs 24.4 in tuareg mode, on OSX 10.9.5, I've installed XQuartz 2.7.7 and tried to tune it (looked here).
I checked whether Graphics is properly installed (and, since all the primitives but "open_graph" work, I think it is) and looked for an answer here and there, but it doesn't really match my problem.

Any idea?

I may mention that, though I'm OK with OCaml, I'm quite new to Emacs (used to work with MacCaml) and totally ignorant about X11.

Community
  • 1
  • 1
S_error
  • 75
  • 1
  • 7

1 Answers1

3

I’m no expert in any of the things you’re using.

However, X11 access to the display is generally controlled by an environment variable named DISPLAY. One possibility is that yours is set to “My-Machine.local”. This doesn’t look right, it just looks like the name of a machine (not a display).

For comparison, the value of DISPLAY on my Mac right now is this:

/private/tmp/com.apple.launchd.4FCqDJISx6/org.macosforge.xquartz:0

If this is meaningful (which it might be), it suggests you need to make sure the value of DISPLAY gets plumbed properly through to X11.

Jeffrey Scofield
  • 65,646
  • 2
  • 72
  • 108
  • Thanks. I tried to understand your answer, and figured a couple of things: `printenv DISPLAY`, when typed in X11's shell gives me `:0`, and nothing when typed in Terminal (it actually doesn't appear in the printenv list). Hence a question: "How do I know what value is supposed to take DISPLAY?" (Again, I am X11-ignorant). I add that I run Emacs from its icon, not from any shell. – S_error May 03 '15 at 16:26
  • I used to be on the Xquartz mailing list. The most usual problem is that people have login files that set DISPLAY. In OS X you do not want to do this, it’s going to be set to a good value for you automatically. The most common erroneous thing to set DISPLAY to is “:0”. So this could be a clue (but not for sure). – Jeffrey Scofield May 03 '15 at 16:28
  • Your "login files" clue made me think about rebooting my computer. Still don't really know why, but it worked: no more "cannot open display" problem. – S_error May 03 '15 at 16:41