问题
I built a Qt application and included the necessary libraries needed in the build directory. When I try to run the application from a different computer, it doesn't work.
This is the ldd
output:
linux-vdso.so.1 => (0x00007fff8c7fe000)
libQt5Widgets.so.5 => not found
libQt5Gui.so.5 => not found
libQt5Core.so.5 => not found
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f5cb4143000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5cb3f2d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5cb3b6c000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5cb3870000)
/lib64/ld-linux-x86-64.so.2 (0x00007f5cb4456000)
The files not found are in the same directory as the binary. How do I make them detectable?
回答1:
On Linux current binary directiry is not the place where the loader looks for shared libraries. See this question: https://serverfault.com/questions/279068/cant-find-so-in-the-same-directory-as-the-executable
回答2:
You can add the following to your .pro file to force the dynamic linker to look in the same directory as your Qt application at runtime in Linux :
unix:{
# suppress the default RPATH if you wish
QMAKE_LFLAGS_RPATH=
# add your own with quoting gyrations to make sure $ORIGIN gets to the command line unexpanded
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
}
来源:https://stackoverflow.com/questions/23896643/qt-program-does-not-detect-libraries