basic usage of X11 functionality on Linux Ubuntu

I am attempting to use X11 capabilities in a test GL ES 3.0 project using CLion
error message:
.... undefined reference to `XOpenDisplay'
.... undefined reference to `glXQueryExtension'
in Cmake file for the project i have the following:

 
cmake_minimum_required(VERSION 2.8.4)
project(tri)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

include_directories(/home/myname/glm /usr/includes/X11 )
set(SOURCE_FILES main.cpp)
add_executable(tri ${SOURCE_FILES})


*******
please note: the glm math library is available in code and to build/run - no errors


the 'usr/includes/X11' path contains Xlib.h - veryfied;

in main.cpp:

*******

#

include <iostream>
#include <GL/glx.h>
#include <EGL/egl.h>
#include <GLES3/gl3.h>
#include <GLES3/gl3ext.h>
#include <glm/glm.hpp>
#include <X11/Xlib.h>
#include <X11/Xlibint.h>


using namespace std;
using namespace glm;

int main() {

    XVisualInfo         *vi;
    Colormap             cmap;
    XSetWindowAttributes swa;
    XEvent               event;
    GLboolean            needRedraw = GL_FALSE, recalcModelView = GL_TRUE;
    GLXContext  fd;


   Display *dsp = XOpenDisplay(NULL); // FAILS TO BUILD here


    Display   *dpy;
    Window     win;
    GLfloat    xAngle = 42.0, yAngle = 82.0, zAngle = 112.0;
    GLboolean  doubleBuffer = GL_TRUE;
    GLint  vart = 1;
    int dummy;

    if(!glXQueryExtension(dpy, &dummy, &dummy)){ // FAILS TO BUILD here

    }
    vec3 Projection = vec3(4.76589f, 1.0f, 1.0f);
    GLint tt = 1;

    cout << "Hello, World! " << Projection.x << " " << tt << endl;
    return 0;
}


******

there are no errors while entering the code in C++ editor of main.cpp, i.e. Cntr+ click on 'XOpenDisplay' and 'glXQueryExtension' will open the Xlib.h in another tab.

I am probably missing something really simple :)

Narkis

6 comments
Comment actions Permalink

Hi,

As I see you use glm lib plus some openGL ES 3.0 lib. I found it not that easy to download exactly the same ES v3.0 headers as you use :/ so would you mind to share that library with me so I can reproduce the problem.

0
Comment actions Permalink

Anyway, even without the part I mentioned previously, I could compile the part of program with XOpenDisplay(NULL) call on my Ubuntu 14.04 with X11 developer package installed (sudo apt-get install libx11-dev). So for now I can suggest the following:

- try to update x11 dev library (or at least locate which package do you use and what is the version)
- verify that your compiler and linker search paths contain paths to X11 (/usr/include/X11 /usr/lib64/X11)

0
Comment actions Permalink

Thanks Maria,

     quick chek on your comment:

- try to update x11 dev library (or at least locate which package do you use and what is the version)

I do have the dev library installed and the header are available as well as the compiled libraries.

- verify that your compiler and linker search paths contain paths to X11 (/usr/include/X11 /usr/lib64/X11)

quoting my Cmake file as it is stripped down just to include the X11 functionality:

make_minimum_required(VERSION 2.8.4)
project(X11test)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)

include_directories(/usr/include/X11) # I assume this is the headers include - the .h files are confirmed there

link_directories(/usr/lib/x86_64-linux-gnu/) # I assume this is linked libraries
  add_executable(X11test ${SOURCE_FILES})

target_link_libraries(X11test libX11.a ) # and this is the linked complied source
   
The result is some errors in the linked library, still no happiness here.
 
One point for me to consider as well is that I would want to be able to compile for different architecture, i.e. ARM - so any libraries would have to be rebuilt for particular architecture.
 
BTW - I do have an exact test project running without errors in code::blocks and using the same includes and libraries.
  
Thanks in advance, and again - I am new to this and any help is appreciated
 
Narkis
   
0
Comment actions Permalink

Ok, with an installed freeglut3-dev and libx11-dev I could build your program using the following CMakeLists.txt

cmake_minimum_required(VERSION 2.8.4)
project(X11WithGLM)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

#all glm headers I moved to /usr/include just beacause it's more convenient for me

add_executable(X11WithGLM main.cpp)

target_link_libraries(X11WithGLM GL X11)

0
Comment actions Permalink

Thanks Maria,

your suggestion is right on!
I just added one line to my Cmake file to include the directories, so my Cmake now builds and runs!

 
cmake_minimum_required(VERSION 2.8.4)
project(X11test)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)

include_directories(/usr/include/X11)

add_executable(X11test ${SOURCE_FILES})

target_link_libraries(X11test X11 )



I will start adding other library headers (GLM, GL, etc) to have those build to several pratforms

Thanks again!
Narkis

0
Comment actions Permalink

I'm glad if I could help.

Currently cross-compilation is not implemented in CLion, here's a related ticket feel free to vote for it. And for now only "Unix Makefiles" cmake generator is suppported.

0

Please sign in to leave a comment.