Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I link to an older version of a shared library

I'm building my program on my computer, on which libtiff.so -> libtiff.so.5. And then pushing the builds on another machine on which libtiff.so -> libtiff.so.4.

At runtime, my program exists : « error while loading shared libraries: libtiff.so.5: cannot open shared object file: No such file or directory ».

I cannot upgrade the other machine, and I would like to avoid compiling on a virtual machine (with the same linux version than the executing machine). Therefore, I would like to force the compiler to use the 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 the linkage with this version instead of the newer version. I thought about moving the libtiff.so -> libtiff.so.4, but I'm afraid of breaking my system if it needs the latest version (apt-get purge libtiff5 gives an error because some other package needs it).

Is it possible to link with an older (installed) version of a library? If yes, how? And is it harmfull to change the symbolic link of libtiff.so to the older version? If not, will it solve my issue?

like image 824
Jav Avatar asked Jan 09 '14 10:01

Jav


People also ask

How do I connect to a shared library?

Shared libraries (also called dynamic libraries) are linked into the program in two stages. First, during compile time, the linker verifies that all the symbols (again, functions, variables and the like) required by the program, are either linked into the program, or in one of its shared libraries.

How do I find shared libraries?

Look under Shared Libraries on the left to see if the Shared Library appears. If it does, you can click on it, and then click the star in the top right to follow it. If it does not appear, click More libraries, and then Go to SharePoint Home. If the Shared Library appears there, click the star beside it to follow it.

How do shared libraries work?

Simply put, A shared library/ Dynamic Library is a library that is loaded dynamically at runtime for each application that requires it. Dynamic Linking doesn't require the code to be copied, it is done by just placing name of the library in the binary file.

How shared library works in Linux?

Shared libraries are the most common way to manage dependencies on Linux systems. These shared resources are loaded into memory before the application starts, and when several processes require the same library, it will be loaded only once on the system. This feature saves on memory usage by the application.


2 Answers

You can use this syntax to link to a specific version of a library:

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

You do not need to specify a path; the usual directories are searched in order to find the library.

Note: as Michael Wild mentioned, you should have the header files for that version installed instead of the newest ones.

like image 119
Nikos C. Avatar answered Sep 28 '22 20:09

Nikos C.


As others have mentioned, you can force the linker by specifying the full versioned name, or even the absolute path.

However, I would strongly advice against doing so. The problem is, that the installed headers correspond to the newer version of the library. If there have been API/ABI-breaking changes between these library versions, the program might work, crash intermittently, or if you're lucky, not work at all.

Instead you should temporarily install the development package that corresponds to the libtiff.so.4 library. If on Debian/Ubuntu or similar, this would be the libtiff4-dev package.

like image 34
Michael Wild Avatar answered Sep 28 '22 21:09

Michael Wild