. Advertisement .
..3..
. Advertisement .
..4..
“Cannot open shared object file no such file or directory” is a common error that show ups in many ways. What is the cause of it and how to fix it? This article will help you answer. Read on it.
How does the error “cannot open shared object file no such file or directory” happen?
Sometimes, you are launching your program, you encounter the following error:
Cannot open shared object file no such file or directory
The reason is that the shared library doesn’t exist or that the program’s libraries are installed in a location where the dynamic linker cannot find them, such as it’s on an unusual path.
How to solve the error “cannot open shared object file no such file or directory”?
Option 1: Try looking for libzstd.so
You can try looking for libzstd.so in your system’s package manager if a software complains about a missing copy.
You can use the apt search command on the apt-based systems as the following:
$ apt search zstd
Sorting... Done
Full Text Search... Done
zstd/stable 1.5.0 aarch64
Zstandard compression.
With apt install, you can now add the missing package. You should be aware that determining the package name using this method needs some guesswork and is not very accurate.
The name of the missing library in the aforementioned example is libzstd.so. However, libzstd is not a package. You must thus make a guess and conduct a simple search for zstd.
Option 2: Utilize ldconfig
A simple method to fix the error “cannot open shared object file no such file or directory” is to utilize ldconfig.
You only need to open a terminal by pressing Ctrl+Alt+T and enter the command below:
sudo /sbin/ldconfig -v
This above liner will fix the problem effectively in most instances. Let’s apply it to get your desired results.
Option 3: Specify the directories
In the LD LIBRARY PATH environment variable, you can specify the directories that will be looked through for shared libraries.
LD LIBRARY_Like the PATH variable, PATH is a list of directories separated by colons.
Usual restrictions on the default search path include /usr/lib and /usr/local/lib. Let’s say you have a program that connects to libfoo.so, which is outside the standard search path at /home/baeldung/libs/libfoo.so. The problem can be resolved then by adding this variable to the search path. Using the ldd command, let’s first confirm the precise libraries that the program links to:
$ ./program
./program: error while loading shared libraries: libfoo.so: cannot open shared object file: No such file or directory
$ ldd ./program
./program:
linux-vdso.so.1 (0x00007ffce871b000)
libfoo.so => not found
libc.so.6 => /usr/lib/libc.so.6 (0x00007fdceadaf000)
/lib/ld-linux-x86-64.so.2 => /usr/lib/ld-linux-x86-64.so.2 (0x00007fdceafd3000)
Let’s make your program work by adding the directory to LD LIBRARY PATH now:
$ export LD_LIBRARY_PATH=/home/baeldung/libs
$ ldd ./program
./program:
linux-vdso.so.1 (0x00007ffe28dfd000)
libfoo.so => /home/baeldung/libs/libfoo.so (0x00007f8f0f7ba000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007f8f0f59d000)
/lib/ld-linux-x86-64.so.2 => /usr/lib/ld-linux-x86-64.so.2 (0x00007f8f0f7c6000)
Additionally, you can find the library by using the find command in well-known paths like /home or /usr if you do not know where it is.
$ find /home -type f -name libfoo.so
/home/baeldung/libs/libfoo.so
Option 4: Install whatever is necessary to make libpthread rt.so.1 available
In that listing, libpthread rt.so.1 is not present. You should either install whatever is necessary to make libpthread rt.so.1 available, or reconfigure and rebuild it such that it depends on the library you already have. For example, if you have version 1.1 of libfoo.so, you’ll have a genuine file libfoo.so.1.0 and symlinks foo.so and foo.so.1 pointing to the libfoo.so.1.0. The numbers after the.so are often version numbers, and you’ll frequently discover that they are symlinks to each other. The libfoo.so.1.1 file will be created if version 1.1 is installed without first uninstalling version 1.0. However, any code that needs version 1.0 can still use the libfoo.so.1.0 file. Code will mention libfoo.so.1 if it just uses the version 1 API and doesn’t care whether it is version 1.0 or 1.1. This is explained effectively here, as orip noted in the comments.
You might be able to get away with symlinking libpthread_rt.so.1 to libpthread_rt.so in your situation.
Coclusion
“Cannot open shared object file no such file or directory” is a confusing problem, but don’t worry. We believe that, with the solutions mentioned above, you can easily fix it. It will quickly disappear. If you still need assistance or have any questions, a growing community of people are usually willing to assist you. In addition, we anticipate a more creative day filled with new ideas and code. Thank you for your reading!
Read more
Leave a comment