Linux dlopen cannot open shared object file no such file or directory

dlopen fails with file not found when file is in correct path

I have a library built using libtool which is install into the package’s library directory, /usr/local/lib/myprog/libmylib.so . I’m dynamically loading the library in my code with libltdl. When I try to load this library on one machine, it works just fine. On another, with the same build and the library installed on the same location, I get a «file not found» error. If I call lt_dlforeachfile directly before lt_dlopenext (which I use to load the library), then I can see by printing out filenames that the library I need has been found in the search path. But then immediately after, loading it fails with a «file not found» error. Any suggestions? UPDATE I have tried switching to using dlopen and explicitly specifying the absolute path to the library. This still works on some systems and not on the other.

1 Answer 1

It turned out that libltdl was hiding the real error. the «file not found» was from another library that the library I was loading depended on. I discovered this when using dlerror() to print the error messages. After installing the missing library, all is well!

Linked

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.12.43529

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

dlopen: libcrypt.so.1: cannot open shared object file: No such file or directory

Some forum threads suggested to reinstall docker-compose, which I did. I tried the following solution, but both without success: Python3.7: error while loading shared libraries: libpython3.7m.so.1.0 How can I resolve this issue?

5 Answers 5

Install libxcrypt-compat from pacman (Official Repositories)

Same thing happened to me today, this is what I did to fix it (Arcolinux 5.16.10-arch1-1)

$ sudo rm -r /usr/local/bin/docker-compose 

Reinstalled it using pip (was not working with the curl method)

$ sudo pip install docker-compose 

Note this installs old (v1) version of docker-compose , while the one being currently developed is v2. Also, manually removing binaries is definitely NOT a recommended way of removing software from any Linux-based system.

@MaksBabarowski: Thank you! I had V1 installed before, so it is suitable for the time being. Docker suggests in their docs to uninstall by remove binaries manually.

I use Arch Linux and it worked for me:

 # cd /usr/lib # sudo ln ./libcrypt.so libcrypt.so.1 # docker-compose -v docker-compose version 1.29.2, build 5becea4c 

The underlying issue here is that you use docker-compose instead of docker compose, which are two different binaries. docker-compose is also known as V1, and is deprecated since April 26, 2022. Since then, it does not receive updates or patches, other than high-severity security patches.

Читайте также:  Tar gz распаковать многотомный архив linux

So, to fix your issue, use docker compose instead of docker-compose . If you compare docker compose version and docker-compose version , you will see that this uses the newer docker compose and runs without an issue.

I found several forum posts explaining to isntall libxcrypt-compat from AUR. I did not like this solution, but apparently, this is the way for now: https://bbs.archlinux.org/viewtopic.php?id=274160&p=2

If there is a PGP key error when building the package from AUR, use this workaround as explained by Stock44 on this page: https://aur.archlinux.org/packages/libxcrypt-compat

$ gpg --keyserver keyserver.ubuntu.com --recv-key 678CE3FEE430311596DB8C16F52E98007594C21D 

Posted on behalf of the question asker

Источник

Linux error while loading shared libraries: cannot open shared object file: No such file or directory

Program is part of the Xenomai test suite, cross-compiled from Linux PC into Linux+Xenomai ARM toolchain.

# echo $LD_LIBRARY_PATH /lib # ls /lib ld-2.3.3.so libdl-2.3.3.so libpthread-0.10.so ld-linux.so.2 libdl.so.2 libpthread.so.0 libc-2.3.3.so libgcc_s.so libpthread_rt.so libc.so.6 libgcc_s.so.1 libstdc++.so.6 libcrypt-2.3.3.so libm-2.3.3.so libstdc++.so.6.0.9 libcrypt.so.1 libm.so.6 # ./clocktest ./clocktest: error while loading shared libraries: libpthread_rt.so.1: cannot open shared object file: No such file or directory 

This might happen if you have recently installed a shared library and didn’t run ldconfig(8) afterwards. Do ‘ldconfig’, there’s no harm in it.

+1 to @AbiusX comment — running sudo ldconfig (assuming that libraries are in fact where they should be [/usr/bin/lib/, /usr/bin/include/, /usr/local/lib/ and /usr/local/include/ AFAIK], please correct me if I’m wrong) can resolve that problem. Cheers!

Note that this error can also arise if the permissions on your lib file got changed somehow. Changing the permissions back to 644 solved it for me.

@AbiusX I ran sudo ldconfig after compiling my program and it worked. Thanks! (The libraries were in /usr/local/lib.)

19 Answers 19

Your library is a dynamic library. You need to tell the operating system where it can locate it at runtime.

To do so, we will need to do those easy steps:

    Find where the library is placed if you don’t know it.

sudo find / -name the_name_of_the_file.so 
LD_LIBRARY_PATH=/usr/local/lib 
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my_library/ export LD_LIBRARY_PATH ./my_app 

The above mentioned answer was very clear, Thanks you first of all. I tried doing this in my Eclipse CDT Project Path (Lubuntu). /Debug$ echo $LD_LIBRARY_PATH /home/akhil/HDE/x86.linux/lib:/home/akhil/HDE/x86.linux/lib.. «/home/akhil/HDE/x86.linux/lib» this is where my libraries are actually available even, but still I get the same error. Any suggestions!

Try a «ldconfig» command after exporting your library. You might need to execute this command as «sudo».

I believe LD_LIBRARY_PATH should point to the directory containing path.so.something , not to path.so.something itself.

This is the right solution for the systems where sudo ldconfig cannot be executed, e.g. supercomputers.

The export LD_LIBRARY_PATH command is essential so that other programs can read the environment variable. Without it only the shell can see the variable.

Here are a few solutions you can try:

Читайте также:  Intel обновление драйверов linux

ldconfig

As AbiusX pointed out: If you have just now installed the library, you may simply need to run ldconfig.

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).

Usually your package manager will take care of this when you install a new library, but not always, and it won’t hurt to run ldconfig even if that is not your issue.

Dev package or wrong version

If that doesn’t work, I would also check out Paul’s suggestion and look for a «-dev» version of the library. Many libraries are split into dev and non-dev packages. You can use this command to look for it:

This can also help if you simply have the wrong version of the library installed. Some libraries are published in different versions simultaneously, for example, Python.

Library location

If you are sure that the right package is installed, and ldconfig didn’t find it, it may just be in a nonstandard directory. By default, ldconfig looks in /lib , /usr/lib , and directories listed in /etc/ld.so.conf and $LD_LIBRARY_PATH . If your library is somewhere else, you can either add the directory on its own line in /etc/ld.so.conf , append the library’s path to $LD_LIBRARY_PATH , or move the library into /usr/lib . Then run ldconfig .

To find out where the library is, try this:

sudo find / -iname *libraryname*.so* 

(Replace libraryname with the name of your library)

If you go the $LD_LIBRARY_PATH route, you’ll want to put that into your ~/.bashrc file so it will run every time you log in:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/library 

By default, /lib and /usr/lib but not /usr/local/lib? That has thrown me off several times over my career and wasted hours.

Adding .conf files of my own with the non-standard lib paths I need to /etc/ld.so.conf.d (pointed to by /etc/ld.so.conf ) did the trick.

+1 for needing to run ldconfig. I wasn’t using a package manager. I had to compile from source, so this was necessary.

Just like @CivFan, I added my own .conf in /etc/ld.so.conf.d . After which I (obviously) had to run ldconfig and it worked. I can feel you @DarenW. Its a pain in the butt

Update
While what I write below is true as a general answer about shared libraries, I think the most frequent cause of these sorts of message is because you’ve installed a package, but not installed the -dev version of that package.

Well, it’s not lying — there is no libpthread_rt.so.1 in that listing. You probably need to re-configure and re-build it so that it depends on the library you have, or install whatever provides libpthread_rt.so.1 .

Generally, the numbers after the .so are version numbers, and you’ll often find that they are symlinks to each other, so if you have version 1.1 of libfoo.so, you’ll have a real file libfoo.so.1.0, and symlinks foo.so and foo.so.1 pointing to the libfoo.so.1.0. And if you install version 1.1 without removing the other one, you’ll have a libfoo.so.1.1, and libfoo.so.1 and libfoo.so will now point to the new one, but any code that requires that exact version can use the libfoo.so.1.0 file. Code that just relies on the version 1 API, but doesn’t care if it’s 1.0 or 1.1 will specify libfoo.so.1. As orip pointed out in the comments, this is explained well at here.

Читайте также:  Linux dev file system

In your case, you might get away with symlinking libpthread_rt.so.1 to libpthread_rt.so . No guarantees that it won’t break your code and eat your TV dinners, though.

Источник

dlopen failed: cannot open shared object file: No such file or directory

The most brutal and effective way to find out where your code goes wrong is the following command which will activate the debugging mode for shared libraries and is documented here:

Then, you will be surprised that so much information pops up. Don’t worry, these information tells you which shared libraries the command you just typed needs and where to locate these needed libraries. For example, if you type reset , the screen will be reseted and then information about the shared libraries reset command needs will be printed.

Then, execute your «problematic» executable to see what’s going wrong.

PS.1 : According to your accepted mythagal’s solution :

Specify the full path to the file in dlopen

dlopen(«/full/path/to/libfile.so»);

It seemed that even though you use absolute or relative path in the dlopen function, the directory not found error will still show up. I am using CentOS, and my Debian is also having this problem. So I think the first solution mythagal provide is wrong. You can verify that in the «debugging» mode I mentioned above.

PS.2: If you «install» or «compile» a shared library rather than install it through package manager, you MUST run sudo ldconfig /path/where/not/found/shared/library/reside to notify the system of the newly added shared library. For example :

cp /etc/ld.so.cache ~/ld.so.cache.backup #cp -r /etc/ld.so.conf.d ~/ld.so.conf.d.backup #sometimes this backup is unnecessary. #cp /etc/ld.so.conf ~/ld.so.conf.backup #sometimes this backup is unnecessary. sudo ldconfig /PATH/WHERE/NOT/FOUND/SHARED/LIBRARY/RESIDE ###I am omitting the cp commands to roll back. ###For example, sudo cp -f ld.so.cache /etc/ld.so.cache 

To understand what’s going on here, please carefully read all the contents in the link above.

PS.3 : You can always use the command export LD_DEBUG=help , export LD_DEBUG=libs to figure out how -rpath or LD_LIBRARY_PATH solve your problem. You will love this debugging mode.

PS.4: A less brutal way to figure out what’s going wrong:

ldd ./YOURproblematicEXECUTABLE 

This command can tell you whether your shared library to be opened is located or not. Besides, there are so many ways to fix your problem and each way has its limitation and application. So I strongly suggested you read the link I provide you above and understand how to choose the way to solve your problem. After reading that, if you actually feel like being very «OK», you can also read this Better understanding Linux secondary dependencies solving with examples for deeper understanding.

Источник

Оцените статью
Adblock
detector