5

For example I am trying to use GLFW3 and it throws the following error at me

x11_init.c:-1: error: undefined reference to `XIQueryVersion'.

I only know that it has something to do with X11 but how do I know which library I have to link? How would you tackle this problem?

Maik Klein
  • 15,548
  • 27
  • 101
  • 197

4 Answers4

7

You could use nm to list the symbols defined in the system libraries in order to find which one contains your missing symbol :

find /usr/lib/ -type f -name \*.a \
  -exec nm -gAC --defined-only {} 2> /dev/null \; \
    | grep \ XIQueryVersion

Which outputs :

/usr/lib/x86_64-linux-gnu/libXi.a:XIQueryVersion.o:00000110 T XIQueryVersion

Then you know you have to link libXi.a, of course you can adjust the library path and symbol name, and that would only work if you already have the right library in your system.

zakinster
  • 10,508
  • 1
  • 41
  • 52
5

I would proceed in this order:

  1. look in the X11 doc to see if they tell you which lib to link to obtain this function
  2. look on the web if you can find a reference to this lib
  3. use nm on the X11 libs to see which one contains this reference

(shhhhhh... it's libxi)

Gui13
  • 12,993
  • 17
  • 57
  • 104
1

I was getting similar linking errors. My error was saying:

/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x16d3): undefined reference to `XIQueryVersion'
/usr/local/lib/libglfw3.a(x11_window.c.o): In function `createWindow':
x11_window.c:(.text+0x6de): undefined reference to `XISelectEvents'

But since I wanted Cmake linking flags for the required linking libs, it took me a while to do so. Required external libs, to compile glfw based program, are:

Requires.private:  x11 xrandr xi xxf86vm gl

This thread shows how to find these libs needed to compile glfw based program.

Since, I spent 2-3 hours looking for Cmake linking flags for the above additional linking libs. I think it's worth mentioning here to help others.

Mainly for the error I have mentioned above, I just needed a cmake linking flag for xi only, but for completeness sake I am mentioning for all of them, i.e. x11 xrandr xi xxf86vm. Here is the snippet from my CMakeLists.txt file:

include_directories(
    ./src
    ${X11_xf86vmode_INCLUDE_PATH}
    ${X11_Xrandr_INCLUDE_PATH}
    ${X11_Xinput_INCLUDE_PATH}
)

    target_link_libraries(
        ${GLFW_LIBRARIES}
        ${X11_LIBRARIES}
        ${X11_Xxf86vm_LIB}
        ${X11_Xrandr_LIB}
        ${X11_Xinput_LIB}
    )

I extracted these flags from this link. Hope, it will save time for others. Enjoy!

Community
  • 1
  • 1
sinner
  • 803
  • 2
  • 11
  • 24
0

I meet this error when I tried to build the OpenGL tutorial code. I fix it by uninstall the libxi-dev package.

I first clean the build directory by

cd build/
rm -r ./*

And then remove the libxi-dev package by

sudo apt-get remove libxi-dev
sudo apt-get autoremove

And rebuild the project by

cd build/
cmake .. # My ogl directory
make all

And then succeed. (Actually I don't know what is the root cause, but it works for me.)

Denny
  • 137
  • 1
  • 6