简体   繁体   中英

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

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.

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 .

you need to compile with:

g++ -o ex ex.cpp -I/usr/X11R6/include -L/usr/X11R6/lib -lX11

the X11 headers are installed with xQuartz , but you need to reference them explicitly

If you install xQuartz it installs into /opt/X11 , and /usr/X11 and /usr/X11R6 are symlinks to this location

这个解决方案对我在Mavericks上的ruby-1.9.3-p362有效。

sudo ln -s /opt/X11/include/X11 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM