1

I have a shared library file part of a larger program. I seem to get many of these errors with all the shared libraries, so I think I've narrowed down my issue to something to do with this.

I have a file called libMdsdcl.so. Just for testing purposes I've placed it in a folder by itself and ran the following lines to repeat the error:

In [1]: import ctypes as c
In [2]: from ctypes.util import find_library
In [3]: name = 'Mdsdcl'
In [4]: libname = find_library(name)
In [5]: c.CDLL(libname)
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-6-7c40f200b197> in <module>()
----> 1 c.CDLL(libname)

/usr/lib/python3.6/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
    346 
    347         if handle is None:
--> 348             self._handle = _dlopen(self._name, mode)
    349         else:
    350             self._handle = handle

OSError: libreadline.so.6: cannot open shared object file: No such file or directory

This isn't my code, but rather it is part of a code that seems to work for everyone who installs it. Based off other similar questions, I checked the architecture of my python installation and the file, and they're both 64-bit. Could something be wrong with my libreadline or something? I actually just upgraded to Ubuntu 18.04 right before this too.

For reference this is MDSplus on the tiny, tiny off chance someone seeing this is familiar with it.

3
  • c.CDLL(libname) is totally incorrect. Specify the lib's whole name: name = "libMdsdcl.so". If that still doesn't work either specify it by its full path, or add its dir in ${LD_LIBRARY_PATH}. Commented May 9, 2018 at 4:24
  • @CristiFati that was my bad typing up the question. I've edited it to what it should've been. It uses find_library to get the library name. Thanks. Commented May 9, 2018 at 14:55
  • You should print(libname) before c.CDLL(libname). Ah, d you have readline package installed? If not, sudo apt-get install libreadline6. Commented May 9, 2018 at 14:57

1 Answer 1

3

You are not showing how you populate name in:

libname = c.CDLL(name)

You may need to ensure you start from the correct directory. os.path.dirname(__file__) will give you this correct directory.

But usually in this context I see something like:

libname = cdll.LoadLibrary(os.path.abspath("libreadline.so.6"))

I think the issue is your path since you don't give the actual extension of the shared object. Try:

name = "libMdsdcl.so"  # or whatever it is called

Just some ideas since I can't tell for sure based on the limited information shown.

Sign up to request clarification or add additional context in comments.

2 Comments

Ah, I'm so dumb. I left out a line in the code. It uses libname=find_library(name). I'll update the question with this.
I have a similar problem, and the line : cdll.LoadLibrary(os.path.abspath("libreadline.so.6") really helped me. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.