X11/Xlib.h not found in Ubuntu

后端 未结 4 408
-上瘾入骨i
-上瘾入骨i 2021-01-30 06:09

I\'m trying to write a rather trivial program using open gl on linux, but at a compile time it says:

Compile thumb : egl <= cuberenderer.c In file i

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 07:03

    Andrew White's answer is sufficient to get you moving. Here's a step-by-step for beginners.

    A simple get started:

    Create test.cpp: (This will be built and run to verify you got things set up right.)

    #include 
    #include 
    
    
    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;
    }
    

    (Source: LinuxGazette)

    Try: g++ test.cpp -lX11 If it builds to a.out, try running it. If you see a simple window drawn, you have the necessary libraries, and some other root problem is afoot.

    If your response is:

        test.cpp:1:22: fatal error: X11/Xlib.h: No such file or directory
        compilation terminated.
    

    you need to install X11 development libraries. sudo apt-get install libx11-dev

    Retry g++ test.cpp -lX11

    If it works, you're golden.

    Tested using a fresh install of libX11-dev_2%3a1.5.0-1_i386.deb

提交回复
热议问题