2

There are two different modules I am trying to load, that link against separate versions of the same shared-library.

Here is the pseudocode for the problem; where UserModule needs the same library and symbols as the initial module.

# dummy load initial module 
import ctypes
ctypes.CDLL('/path/to/different/libname.so')

# load another module
import UserModule

ImportError: /path/to/UserModule/libUserModule.so: undefined symbol

I can delete the initial shared library using ctypes.CDLL('libdl.so').dlclose(), and then load the next library. But I want a method to them both loaded in memory at the same time without having this messiness.

I also tried to use

# try to load memory locally
import sys
import DLFCN
sys.setdlopenflags( DLFCN.RTLD_NOW | DLFCN.RTLD_LOCAL )

# dummy load initial module
import ctypes
ctypes.CDLL('/path/to/different/libname.so')

# load another module
import UserModule

But it fails with the same error.

Is there any way to load a module with the same name into memory in python, to be usable with different modules?

Edit: To be more precise with the question. Python loads in a shared library into memory. When I try to import another module which links to a different shared library with the same name, it seems that python is not loading in this new shared library. Why would this occur?

WolcottR
  • 55
  • 5
  • 1
    It's possible to have the same *.dll* loaded in the current process, as far as it resides in different directories. https://stackoverflow.com/questions/54243176/independent-cdll-library-instances-with-ctypes/54257116#54257116. – CristiFati Apr 25 '19 at 09:16
  • @CristiFati thank you for the link. I am not surprised by that behavior, but I am glad to hear it is true. I was more curious about why python seems to, once it's loaded in a shared library, not load in another different shared library with the same name. – WolcottR Apr 25 '19 at 19:04
  • It's more like a loader "problem" rather than *Python*. – CristiFati Apr 25 '19 at 22:02

0 Answers0