I'm developing a shared library, and on my machine there could be two copies of the same shared library:
- the one I installed to the system path:
/usr/lib/libmyproject.so
- the one I built in my workspace during my development:
/home/ziqi.liu/workspace/myproject/build/src/libmyproject.so
So during my development, there're some executables under /home/ziqi.liu/workspace/myproject/build
. I want them to use the dynamic library in /home/ziqi.liu/workspace/myproject/build/src/libmyproject.so
, however it turns out that they're actually using /usr/lib/libmyproject.so
when I use ldd
to check the link library.
Is there anyway to specify which dynamic library to use when there are multiple? It would be better if I can specify this for all executables under "this project", since it's very intuitive to link the dynamic library in the same repo I just built, instead of the one installed to the system path.
UPDATED: I've found this post: Where do executables look for shared objects at runtime?
It seems that the dynamic library searching has something to do with
the rpath
and LD_LIBRARY_PATH
environment variables.
What I want is to search for rpath
first, and then LD_LIBRARY_PATH
.
According to rpath wiki, the rpath
is named DT_RPATH
, however when I objdump
that executable, the only thing I can find is RUNPATH
section. I'm not sure if this is a compiler-specific behavior... (I'm running g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
)