http://stackoverflow.com/questions/16587828/how-to-link-an-unknown-library
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.