Methods of payment Abuse

Ошибка error while loading shared libraries

21.02.2024, 22:45

Linux users often encounter the error error loading shared libraries when running programs, it is also familiar to many programmers and anyone wishing to compile software on their system. Literally, it means that there is a problem while loading shared libraries.

Read more about the error error while loading shared libraries

Error"error while loading shared libraries" means that when running a program or script, the operating system could not find and load one or more libraries that are necessary for this program to work. This is a common problem in UNIX-like operating systems. When a program is compiled, it may refer to various external libraries that must be available at runtime. If these libraries are missing or unavailable, an error while loading shared libraries occurs.

Even if you do not compile your programs, you may see this error: directory_name: cannot open shared object file: No such file or directory quite often when installing new programs not through the package manager or programs intended for another distribution. It occurs because the system cannot find the library. Why can't it be found and loaded?

Several reasons, as a rule it all comes down to a library that:

  • is not installed on the system;
  • is installed, but it's in the wrong place;
  • is installed correctly but has the wrong version.

When solving the problem, we will be guided by these reasons and try to solve them.

How to fix the error error loading shared libraries?

Next, let's consider specific examples of solving this problem based on the reasons mentioned in the previous paragraph.

Library is not installed

There is nothing complicated here and everything is quite clear - the library is simply not present in the system, that's why we get this error. That's why we need to find the library package with the help of a package manager and install it. Usually, packages with libraries are called the same as the libraries themselves with the prefix lib.

If we are missing the libfuse2.so library, we can find it in Ubuntu with this command:

$ sudo apt search libfuse2

Then the only thing left to do is to install it:

$ sudo apt install libfuse2

When you need to build a program from source, you will also have to install the header files:

$ sudo apt install libfuse-dev

And so for any library. But this doesn't always work.

The library is in the wrong directory

In practice, there are cases when the library is installed, but the error persists and does not allow users to interact normally with the system. What to do in such a case? First of all, check the Linux boot loader that cannot find the library. The search should be performed in the directories specified in the configuration files /etc/ld.conf.d/. As a rule, these are /usr/lib, /lib, /usr/lib64, /lib64. If the library is installed in a different directory, this is obviously the root of the problem.

You can see what libraries are currently available to the loader using the command:

$ ldconfig -p

Find where your library is located using the locate command. For example, we are interested in the library librtfreader.so:

$ locate librtfreader

When we know the location of /opt/kingsoft/wps-office/office6/, we need to make it possible for the loader to locate the library. We add the path /etc/ld.so.conf.d/ to the configuration file or to the LD_LIBRARY_PATH variable:

export LD_LIBRARY_PATH=/opt/kingsoft/wps-office/office6/

You can install with any library that invokes the error. You can also take the less complicated route of creating a symbolic link to the correct library in the correct directory:

ln -s /opt/kingsoft/wps-office/office6/librtfreader.so /usr/lib/librtfreader.so

Invalid library version

This usually happens when using programs for a distribution that you do not have installed. Each library has an additional version, which is written after the .so extension. For example, libav.so.1. The version number changes whenever a library is patched.

It is often the case that in one distribution a program is built with a library dependency, such as libc .so.1, and in another distribution there is only libc.so.2. In most cases the differences here are small and the program could run on the second version of the library. So we can simply create a symbolic link to it.

For example, there is no libusb-1.0.so.1 library. But there is libusb-1.0.so.0.1, and we can use it:

To do this, we simply create a symbolic link to the library:

$ sudo ln -s /usr/lib/libusb-1.0.so.0.1 /usr/lib/libusb-1.0.so.1

Often the program will not notice the substitution and will work. As a smart solution, try to find the right version of the library on the Internet for your architecture and place it in the /usr/lib/ or /usr/lib64/ folder. But after that it is desirable to update the cache:

$ sudo ldconfig

If the problem does not solve after these steps, it is recommended to refer to the documentation of the program or operating system for more detailed information about the required library versions and how to install them.