How can I link the old version of the shared library

I create my program on my computer on which libtiff.so -> libtiff.so.5 . And then we push assemblies to another machine on which libtiff.so -> libtiff.so.4 .

At runtime, my program exists: "error loading shared libraries: libtiff.so.5 : cannot open shared object file: there is no such file or directory."

I cannot upgrade another machine, and I would like to avoid compiling on a virtual machine (with the same version of Linux as the executing machine). Therefore, I would like to force the compiler to use libtiff.so.4 instead of libtiff.so.5 .

I have libtiff.so.4 installed on my computer (as well as libtiff.so.5 ). How can I force binding to this version instead of the new version. I was thinking of moving libtiff.so -> libtiff.so.4 , but I'm afraid to break my system if it needs the latest version ( apt-get purge libtiff5 gives an error because it needs some other package).

Can I link to the old (installed) version of the library? If so, how? And is it harmful to change the libtiff.so symbolic link to an older version? If not, will he solve my problem?

+6
source share
3 answers

This syntax can be used to reference a specific version of the library:

  gcc [other options] -l: libtiff.so.4

You do not need to specify a path; ordinary directories search to find a library.

Note: as Michael Wilde mentioned, you must have the header files for this version, not the latest.

+2
source

As already mentioned, you can force the linker to specify the fully qualified version name or even the absolute path.

However, I would strongly advise doing this. The problem is that the installed headers correspond to the new library version. If there are API / ABI changes between these versions of the library, the program may work, crashing periodically, or if you are lucky, do not work at all.

Instead, you should temporarily install the development package corresponding to the libtiff.so.4 library. If on Debian / Ubuntu or similar, it will be the libtiff4-dev package.

+1
source

Specify the full path to .so: instead of -ltiff pass /lib64/libtiff.so.4 to the linker.

0
source

All Articles