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?
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.
I would proceed in this order:
nm
on the X11 libs to see which one contains this reference(shhhhhh... it's libxi
)
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With