在Ubuntu中找不到X11/Xlib.h

Den*_* S. 59 linux compiler-errors opengl-es

我正在尝试使用linux上的open gl编写一个相当简单的程序,但在编译时它说:

编译拇指:egl <= cuberenderer.c在/path/include/egl.h:36中包含的文件中,来自/path/cuberenderer.c:7:/path/include/eglplatform.h:89:22:错误:X11 /Xlib.h:没有这样的文件或目录/path/include/eglplatform.h:90:23:错误:X11/Xutil.h:没有这样的文件或目录

我对GL完全不熟悉,也不知道出了什么问题.

And*_*ite 142

使用快速搜索...

apt search Xlib.h
Run Code Online (Sandbox Code Playgroud)

打开包libx11-dev但是你不需要这个用于纯OpenGL编程.你在用什么教程?

您可以通过运行以下命令将Xlib.h添加到您的系统中...

sudo apt install libx11-dev
Run Code Online (Sandbox Code Playgroud)

  • 最后一次编辑用 `apt search` 替换了 `apt-file search`,但在 Ubuntu 18.04 中,`apt search` 似乎只搜索包(如 `apt-cache`)。到目前为止,我只使用了 `apt` 作为改进的 `apt-get`/`apt-cache`。如果单独使用 `apt` 对您不起作用,请尝试使用 `apt-file`。 (2认同)

小智 28

假设他正在使用来自http://www.arcsynthesis.org/gltut/的教程以及premake4.3 :-)

sudo apt-get install libx11-dev................. ........ X11/Xlib.h
sudo apt-get install mesa-common-dev........ GL/glx.h
sudo apt-get install libglu1-mesa-dev..... GL/glu.h
sudo apt-get install libxrandr-dev....... X11/extensions/Xrandr.h
sudo apt-get install libxi-dev..... ..............X11/extensions/XInput.h

之后我可以构建glsdk_0.4.4和示例而无需进一步的问题.


小智 8

安德鲁怀特的回答足以让你感动.这是初学者的一步一步.

一个简单的入门:

创建test.cpp :(这将构建并运行以验证您是否已正确设置.)

#include <X11/Xlib.h>
#include <unistd.h>


main()
{
  // Open a display.
  Display *d = XOpenDisplay(0);

  if ( d )
    {
      // Create the window
      Window w = XCreateWindow(d, DefaultRootWindow(d), 0, 0, 200,
                   100, 0, CopyFromParent, CopyFromParent,
                   CopyFromParent, 0, 0);

      // Show the window
      XMapWindow(d, w);
      XFlush(d);

      // Sleep long enough to see the window.
      sleep(10);
    }
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

(来源:LinuxGazette)

尝试:g++ test.cpp -lX11 如果它构建为a.out,请尝试运行它.如果您看到一个简单的窗口,您将拥有必要的库,并且正在进行其他一些根问题.

如果您的回复是:

    test.cpp:1:22: fatal error: X11/Xlib.h: No such file or directory
    compilation terminated.
Run Code Online (Sandbox Code Playgroud)

您需要安装X11开发库. sudo apt-get install libx11-dev

重试 g++ test.cpp -lX11

如果它有效,你就是金色的.

使用全新安装的libX11-dev_2%3a1.5.0-1_i386.deb进行测试


Zoh*_*zai 7

为什么不尝试一下find /usr/include/X11 -name Xlib.h

如果有命中,你就有了 Xlib.h

如果没有安装它使用sudo apt-get install libx11-dev

你就可以走了:)