I am trying to run my application which requires a dependency libother
; and libother
requires its own dependency libfftw3
. Both dependencies are located in the same folder on Ubuntu 22.04 LTS. I build my application using Qt and specify the runtime path inside my .pro
file:
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
# Library runtime location
unix{
QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'"
}
SOURCES += \
main.cpp
# Include path
INCLUDEPATH += $$PWD/include/
# Libraries
LIBS += -L$$PWD/bin/ -lother
What is so strange is that when I run the application, it is able to find the one dependency and not the other even though they are both located in the same place specified by -rpath
:
ldd my_app
libother.so.1 => /my_app_path/libother.so.1 # Path specified by -rpath
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 # System lib path
libfftw3.so.3.6.9 => not found # This lib is in the same location as libother.so.1 but isn't found?
If I manually add my_path
to my runtime path, then it loads fine. It just makes no sense.
RPATH
and RUNPATH
apply to resolving shared objects directly listed as needed by the same shared object in which they themselves appear. Those have their own lists of needed shared objects, and (only) their own RPATH
or RUNPATH
entries are used to resolve references to those. This was apparently your issue. Your main executable object did not link directly to libfftw3, so its RPATH
was not relevant to loading it. Your libother
did link to libfftw3
, but it did not have an RPATH
entry by which to locate that library outside the default library search path.