Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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`
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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