Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.