16

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.

Mat
  • 202,337
  • 40
  • 393
  • 406
David Polák
  • 1,581
  • 4
  • 18
  • 33

2 Answers2

25

I've figured it out.

Adding -lX11 to the the Makefile solved this issue.

user-id-14900042
  • 686
  • 4
  • 17
David Polák
  • 1,581
  • 4
  • 18
  • 33
  • 1
    where do you add in Qt Creator – Minimus Heximus Sep 02 '13 at 06:16
  • 1
    Projects - Build steps - Additional arguments – David Polák Sep 02 '13 at 16:12
  • 3
    @Meltea This doesn't seem to work on qmake in Qt 5.5.1 How do I make it work? It is saying that -lX11 is not a known argument. – Menno van Leeuwen Apr 04 '16 at 03:23
  • What make file? There isn't a make file mentioned in the question. – Rebroad Mar 11 '21 at 11:13
  • I'm getting the same error calling the make file for [another project](https://github.com/jumper149/blugon), and the surprising thing is that if I pull out all the flags used in the makefile and call gcc in the command line e.g. `gcc scg.c -O2 -std=c11 -D_POSIX_C_SOURCE=200809L -Wall -Wextra -Wpedantic -lX11 -lXrandr -o scg`, then it compiles & links, but calling it with Make it does not work. How can this be?? – Orco May 03 '22 at 21:27
2

@КодСерфинг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.