There is a list of common errors I often see in Ubuntu. There is
One of such common errors which I often see while installing a program from its source code is
error while loading shared libraries:
cannot open shared object file: No such file or directory
For example, I was trying to use FreeRADIUS server and it showed me this error:
radiusd : error while loading shared libraries:libfreeradius -radius-2.1.10.so:
cannot open shared object file: No such file or directory
The reason behind this error is that the libraries of the program have been installed in a place where dynamic linker cannot find it.
Fix ‘cannot open shared object file: No such file or directory’ error
In this quick tutorial, I’ll show you the quickest and the easiest way to fix this error while loading shared libraries.
All you need to do is to open terminal (Ctrl+Alt+T) and type the following command:
sudo /sbin/ldconfig -v
This
What are shared object files? How does the above command fixes the issue?
You see, in C/C++, a .so (shared object) is a compiled library file. It is called shared object because this library file can be shared by several programs. These generated libraries are usually located in /lib or /usr/lib directories.
Now if you wonder how did this tiny command fixed this problem, you should read the man page of
ldconfig creates the necessary links and cache to the most recent shared libraries found in the directories specified on the command line, in the file /etc/ld.so.conf, and in the trusted directories (/lib and /usr/lib). The cache is used by the run-time linker, ld.so or ld-linux.so. ldconfig checks the header and filenames of the libraries it encounters when determining which versions should have their links updated.
I hope this quick fix helps you in eliminating the nasty error while loading shared libraries message in Ubuntu and other Linux.
If not, you can do some investigation and try to fix the issue the way it is mentioned in the next section.
Alternate method to fix ‘cannot open shared object file’ error
The above discussed method fixes the issue if the library in question is available in your system. But that may not always be the case.
If you do not have the program installed on your system, you won’t have its library file. The ldconfig cannot do anything if there is no library file in the first place.
So, the alternate method is to install the required program and it should create the library automatically.
Let me show it to you by an example. Let’s say you see this error:
error while loading shared libraries: libgobject-2.0.so.0: cannot open shared object file: No such file or directory
The problem is with libgobject version 2.0. The version number is important because some programs depend on a specific version of the library and if they don’t find, they complain about it.
Now, apt provides the search option that can be used for searching a package and knowing its version before installing it.
[email protected]:~$ apt search libgobject
Sorting... Done
Full Text Search... Done
librust-gobject-sys-dev/focal 0.9.0-2 amd64
FFI bindings to libgobject-2.0 - Rust source code
Now, this librust-gobject-sys-dev package could be what you need if you know that you were trying to run a Rust program. But what if it was a Python program you were running that complained about it?
You can widen your search by removing the lib from the package name while searching. The lib signifies library and libraries may be provided by a generic package that could be named gobject-xyz.
It would be a good idea to search for the string in the names of the package (instead of description) to get more concise results.
[email protected]:~$ apt search --names-only gobject
Sorting... Done
Full Text Search... Done
gobject-introspection/focal-updates 1.64.1-1~ubuntu20.04.1 amd64
Generate interface introspection data for GObject libraries
libavahi-gobject-dev/focal 0.7-4ubuntu7 amd64
Development headers for the Avahi GObject library
libavahi-gobject0/focal 0.7-4ubuntu7 amd64
Avahi GObject library
libcairo-gobject-perl/focal,now 1.005-2 amd64 [installed,automatic]
integrate Cairo into the Glib type system in Perl
libcairo-gobject2/focal,now 1.16.0-4ubuntu1 amd64 [installed,automatic]
Cairo 2D vector graphics library (GObject library)
libghc-gi-gobject-dev/focal 2.0.19-1build1 amd64
GObject bindings
libghc-gi-gobject-doc/focal,focal 2.0.19-1build1 all
GObject bindings; documentation
In the above truncated output, you’ll have to see if the package is related to the original program you were trying to run. You must also check the version of the library provided.
Once you have identified the correct package, install it like this:
sudo apt install package_name
Once installed, you may run the ldconfig command again to update the cache:
sudo /sbin/ldconfig -v
This method requires some effort on your end but this is how the dependencies are handled.
Nothing works, what now?
If you are unfortunate enough, the above methods might not work for you. What can you do?
First, keep in mind that the shared libraries may be used from other packages in some cases. If you were trying to run XYZ program and ABC program installs the correct version of the shared library, it may (or may not) work for you. You can give it a hit and trial.
Second, if you are trying to run a program which is too old or too new, it may require a library version which is not available for your Linux distribution.
What you may do is to check if you can use some other version of the program. For example, using Eclipse version 3 instead of version 4. This may help your case.
The other way would be to check the developers website or forums and see if you can manually install the correct version of the library from its source code. That requires a lot of effort (in 2020) but you don’t have a lot of options.
Did it work for you?
I hope I have make things a bit more clear for you. Did you manage to fix the issue of shared libraries in your system? If you have questions, suggestions, feel free to drop a comment. Ciao :)
Great article! You saved lots of my time and others!
Happy to be of help.
Hi.. I am trying to run a software called “Salome” in ubuntu 16.04. I am getting an error with libGLX.so.0: cannot open shared object file: No such file or directory.
I tried your methods in the blog mentioned. But nothing is happening.
Can you please shed a light on this..?
Thanks and Regards,
Sunag R A.
Try installing libglx? It should be in a package like libglx-dev.
Hi..I did the two steps below now and before:
1. sudo apt-get update
2. sudo apt-get install libglx-dev
But the result showed:
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package libglx-dev
Even I tried to find the libGLX file using apt-file find. It is showing in nvidia folder. But my laptop is of AMD.
Anyways how can I install libglx-dev if it is unable to locate package?
Thanks and regards,
Sunag R A
Just checked. It is not available for Ubuntu 16.04.
On the download page of Salome, I can see several versions and one of them is Ubuntu 16.04.
Did you download the version specified for 16.04?
Anyways, try getting the libglx deb file from the debian repository here: https://packages.debian.org/buster/amd64/libglx0/download
Install it and see if it fixes the problem.
Hi,
Thanks for digging into Salome and checking out.
1. Yes, I did install the correct version 16.04, also check with Universal linux binary as mentioned in one of the salome forum.
2. Now, I did install libglx deb from the link you have provided. I added the deb http:// line into /etc/apt/sources.list and ran
a. sudo apt update.
But I did get this error:
E: The repository ‘http://ftp.debian.org/debian buster InRelease’ is not signed.
I tried installing by downloading the deb file from the link. It is unable to install from Ubuntu software app.
Regards,
Sunag R A.
If the double clicking on the deb file doesn’t work, maybe you can try using the command line version and see if it shows any error.
host: error while loading shared libraries: libdns.so.1605: cannot open shared object file: Error 40