Undefined reference to XOpenDisplay in a Qt project
Asked Answered
M

2

17

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.

Moonseed answered 4/6, 2010 at 15:0 Comment(1)
@cz-david Did you add XLib to LIB in your Qt project file?Leix
M
28

I've figured it out.

Adding -lX11 to the the Makefile solved this issue.

Moonseed answered 4/6, 2010 at 15:15 Comment(5)
where do you add in Qt CreatorBebeeru
Projects - Build steps - Additional argumentsPikeman
@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.Triton
What make file? There isn't a make file mentioned in the question.Isobaric
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?? 😠Viperish
C
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.

Chrysoberyl answered 3/11, 2018 at 2:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.