“X11 / Xlib.h”:mac os x mountain lion上没有这样的文件或目录

当我编写一个简单的程序时,我遇到了这个:

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

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

你需要编译:

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

X11标头随xQuartz一起安装,但您需要显式引用它们

如果你安装xQuartz它安装到/opt/X11/usr/X11/usr/X11R6是这个位置的符号链接

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

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

就我而言,我必须在usr/local下创建include目录。

这个解决方案适用于我在小牛队的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/