Linux – Error soname for Ubuntu loading shared libraries at runtime

Error soname for Ubuntu loading shared libraries at runtime… here is a solution to the problem.

Error soname for Ubuntu loading shared libraries at runtime

I’m using eclipse cdt to compile and run a C++ application.

My_main_program specifically requires libjpeg.so.62.

My Ubuntu system used to have libjpeg.so.9 in /usr/local/lib/. I happened to compile and run with libjpeg.so.9 before throwing the runtime compatibility error.

Then I removed all libjpeg.* from the source code and installed libjpeg.la, libjpeg.so, libjpeg.so.62, and libjpeg.so.62.0.0. Then I run ldconfig.

I can build the project. The problem is that the dynamic linker keeps searching for libjpeg.so.9 and throwing

'Error loading shared library: libjpeg.so.9: Unable to open shared object file: There is no such file or directory'

At runtime.
This question is dying.
I checked that the symbolic link of libjpeg.so is correct.
Please help!

Solution

I can build the project. The problem is the dynamic linker keeps searching for libjpeg.so.9 and throwing

'error while loading shared libraries: libjpeg.so.9: ... No such file ...

There are a few things you need to know:

  1. Shared libraries may have SONAME dynamic tags (visible via readelf -d foo.so | grep SONAME).
  2. If an executable links to such a library, the SONAME will be recorded as a NEEDED dynamic tag (in the executable), regardless of the name of the library itself. That is, you can name the library foo.so, foo.so.1234, or any other name. If the library has SONAME for libbar.so.7, then the executable will need libbar.so.7, whatever [1].

About your question. Your executable fails to load libjpeg.so.9, so we conclude that it is > (at build time) linking with a shared library with SONAME: libjpeg.so.9

I deleted all libjpeg.* and installed libjpeg.so.62

You cannot delete the libjpeg.so used when building can be executed (outside of /usr/local/lib). That library still has SONAME: libjpeg.so.9, which makes you sad.

You can find out which libraries were being used at the time of the link by passing the –wl,-t flag on the link line.

[1] Not exactly: if the executable does not require any symbols from foo.so, and if the –-as-needed linker option is valid, then NEEDED: libbar.so.7 will not be logged after all.

Update:

I have also check ldd executable and it returns libjpeg.so.62

This means that the executable file you are running ldd is correct, but the executable that is actually running is not, they must be different executables.

Update 2:

You’re right. ldd executable shows both libjpeg.so.62 and libjpeg.so.9 are included

Actually, no, I’m not. But this time I will be right.

What happens is that your executable correctly records NEEDED: libjpeg.so.62 (you can verify this using readelf -d/path/to/exe | grep 'need.) *libjpeg').

But you have some other shared libraries (one listed in the ldd output) that have not been rebuilt and still depend on libjpeg.so.9.

You can find the library by running readelf -d/path/to/libXXX.so |. grep 'NEEDED.*libjpeg\.so\.9' on all libraries listed in the ldd output.

Once it is found, it must be rebuilt, so it also relies on libjpeg.so.62.

Related Problems and Solutions