5

I am trying to build a small Qt (C++) GUI application on Linux but it fails to build with numerous linker errors, complaining about missing dependencies for the Qt library I am linking against. I used ldd on the Qt libraries to verify that the libraries are indeed there - and they are.

My problem seems to be related to the discussion in this thread: Linking dependencies of a shared library And while that thread helped me identify my precise problem, it seems that the conclusion of that thread was that my application should link!

The application is compiled with the following command:

g++ -m64 -Wl,-O1 -o Executable some-object.o some-other-object.o -lQtCore -lQtGui -lQtXml -L/usr/lib64 -L/usr/X11R6/lib64 -lpthread

Running this generates warnings of the following form, and linking eventually fails with undefined reference errors (to symbols defined in the 'missing' libraries):

.../ld: warning: libglib-2.0.so.0, needed by /usr/lib64/libQtGui.so, not found (try using -rpath or -rpath-link)
.../ld: warning: libpng14.so.14, needed by /usr/lib64/libQtGui.so, not found (try using -rpath or -rpath-link)
.../ld: warning: libz.so.1, needed by /usr/lib64/libQtGui.so, not found (try using -rpath or -rpath-link)
.../ld: warning: libfreetype.so.6, needed by /usr/lib64/libQtGui.so, not found (try using -rpath or -rpath-link)

and so on (in total there are 18 dependencies that could not be found.)

I can get this to compile if I go and explicitly add -lglib, -lpng14, -lz -lfreetype and so on, but as I mentioned there are 18 dependencies - and I would rather not do that. It also seems that I should not have to do it.

I have compiled the same project on my laptop computer which uses the exact same Linux Distro (openSuse 12.2) without any troubles. All libraries, including Qt, were installed from the distro repositories.

I think this might be some sort of setup problem on my openSuse install, but I have no idea where to start looking to fix this.

Cheers, Craig

Community
  • 1
  • 1
  • I agree that it should Just Work without you having to add all the dependent libraries. I'd suspect a system misconfiguration of some sort. Perhaps reinstalling pieces of the toolchain, such as the compiler and binutils, might help...? – Jamey Sharp Nov 12 '12 at 17:41
  • Using Yast I removed binutils, then reinstalled the gcc tools and now it works. Thanks for your reply. – Craig Dillabaugh Nov 12 '12 at 19:17

1 Answers1

1

It appears that /usr/lib64/libQtGui.so have hardcoded rpaths in them to locate dependent shared libraries. On one of your hosts the needed libraries are in the expected location while on the other host they are not.

You can use something like elfdump to get the RPATH out of the QT shared library to find out where it will look. Then you can use (I believe) -R on your link command line to point it to where the libraries are actually installed on that host.

EDIT: I think you can do something like objdump -x <binary/library> | grep -i rpath

Mark B
  • 95,107
  • 10
  • 109
  • 188
  • Following Jamey's suggestions above fixed things for me, but just as a follow up on your answer. openSuse doesn't come with elfdump . Any idea how I would find RPATH embedded in an elf file on this system. I tried objdump and readelf, and found references to the libraries in their output, but nothing about an RPATH. – Craig Dillabaugh Nov 12 '12 at 19:20
  • I use `chrpath` for that. In Debian, it's in the `chrpath` package, unsurprisingly. :-) I imagine `objdump` would work too, but if there's no rpath in the binary, you simply won't see any output, so it's hard to tell whether it's working without finding an rpath-encumbered binary to test on too. – Jamey Sharp Nov 12 '12 at 21:40