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.

1
  • 1
    @cz-david Did you add XLib to LIB in your Qt project file?
    – mosg
    Jun 4, 2010 at 15:14

2 Answers 2

25

I've figured it out.

Adding -lX11 to the the Makefile solved this issue.

5
  • 1
    where do you add in Qt Creator Sep 2, 2013 at 6:16
  • 1
    Projects - Build steps - Additional arguments Sep 2, 2013 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. Apr 4, 2016 at 3:23
  • What make file? There isn't a make file mentioned in the question.
    – Rebroad
    Mar 11, 2021 at 11:13
  • I'm getting the same error calling the make file for another project, 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 3, 2022 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.