I have a binary executable named "alpha" that requires a linked library (libz.so.1.2.7) which is placed at /home/username/myproduct/lib/libz.so.1.2.7
I export the same to my terminal instance before spawning my binary executable by executing the following command.
export LD_LIBRARY_PATH=/home/username/myproduct/lib/:$LD_LIBRARY_PATH
Now, when I spawn another application "bravo" that requires the same library but of different version, i.e (libz.so.1.2.8) which is available in
/lib/x86_64-linux-gnu/libz.so.1.2.8
, system throws the following error.
version `ZLIB_1.2.3.3' not found (required by /usr/lib/x86_64-linux-gnu/libxml2.so.2)
If I unset the LD_LIBRARY_PATH
, "bravo" starts up fine. I understand that the above behaviour is because LD_LIBRARY_PATH
takes precedence over the directory paths defined in /etc/ld.so.conf
while looking for linked libraries and consequently the above error occurred. I am just curious about why have not the developers of UNIX/LINUX designed the OS to search for linked libraries in other directories according to the hierarchy if the first instance of library is of different version.
Simply put, UNIX/LINUX systems traverse through a set of directories until it finds the required library. But why does it not do the same until it finds the expected version rather than accepting the first instance of library irrespective of its version?
libz.so.1
is a symlink tolibz.so.1.2.8