C语言 “X11/Xlib.h”:mac os x 山狮上没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14321038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 05:02:13  来源:igfitidea点击:

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

cx11osx-mountain-lion

提问by jasonkim

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.

仅供参考,我安装了 xQuartz。我用“g++ -o ex ex.cpp -L/usr/X11R6/lib -lX11”命令编译这个程序。

采纳答案by Petesh

you need to compile with:

你需要编译:

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

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

X11头文件被安装有xQuartz,但你必须明确地引用它们

If you install xQuartzit installs into /opt/X11, and /usr/X11and /usr/X11R6are symlinks to this location

如果您安装xQuartz/opt/X11,它会安装到,/usr/X11并且/usr/X11R6是指向此位置的符号链接

回答by skndmx

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

您可能需要通过以下方式将符号链接添加到 X11 文件夹:

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

须藤 ln -s /opt/X11/include/X11 /usr/local/include/X11

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

就我而言,我必须在usr/local.

回答by vglafirov

This solution worked for me for ruby-1.9.3-p362 on 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/