Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to XOpenDisplay in a Qt project

Tags:

c++

qt

xlib

Now I am feeling quite stupid. I am trying to do some stuff with xlib in Qt Creator.

My code:

#include <QtCore/QCoreApplication>
#include <X11/Xlib.h>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    Display *display = XOpenDisplay(NULL);

    return 0;
}

Just one line of code and gives me:

/main.cpp:8: undefined reference to `XOpenDisplay'

It is defined in Xlib.h as

extern Display *XOpenDisplay(
    _Xconst char* /* display_name */
);

I feel I am missing something very basic.

like image 959
David Polák Avatar asked Jun 04 '10 15:06

David Polák


2 Answers

Found it... compiler problem

added -lX11 to the make file

like image 118
David Polák Avatar answered Oct 25 '22 16:10

David Polák


@КодСерфинг145 I added LIBS += -lX11 to the make file (the .pro file) Adding Additional arguments to Build steps inside Projects did not work for me either and neither did QMAKE_CXXFLAGS += -lX11 like many suggests.

like image 26
Zander Labuschagne Avatar answered Oct 25 '22 18:10

Zander Labuschagne