3

I am try to compile a simple codebase that use simple X11 functions but it gives error at compile:

(.text+0x1c): undefined reference to `XShmQueryVersion'

I used the XShmQueryVersion function in my code, I compiled it with

g++ myprogram.c -o program

What am I missing?

1 Answer 1

4

You need to tell the compiler what libraries to find the X11 functions in. The core X functions like XOpenDisplay are in libX11, while extensions are in additional libraries - like libXext for XShmQueryVersion.

The direct way to tell your compiler to link with these libraries is via -l flags:

g++ myprogram.c -o program -lXext -lX11

Once you get to building larger software, with Makefiles & such, there are tools to help manage the flags for these libraries, and you might have something in your Makefile such as:

CFLAGS += `pkg-config --cflags x11 xext`
LIBS += `pkg-config --libs x11 xext`

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .