"X11/Xlib.h": no such file or directory on mac os x mountain lion

jasonkim picture jasonkim · Jan 14, 2013 · Viewed 26.1k times · Source

I came across this when I was compiling a simple program:

 #include <X11/Xlib.h>
 #include <stdio.h>
 #include <stdlib.h>

 Display* display;

 int main(){
     display = XOpenDisplay("");
     if (display == NULL) {
         printf("Cannot connect\n");
         exit (-1);
     }
     else{
         printf("Success!\n");
         XCloseDisplay(display);
     }
  }

FYI, I have xQuartz installed. I compile this program with "g++ -o ex ex.cpp -L/usr/X11R6/lib -lX11" command.

Answer

skndmx picture skndmx · Sep 26, 2013

You may need to add symbolic link to X11 folder by:

sudo ln -s /opt/X11/include/X11 /usr/local/include/X11

In my case, I had to make include directory under usr/local.