By default, the interpreter will not load extensions in a way that will share symbols across extensions. This can be modified by setting the dlopen()
flags used by the interpreter via sys.setdlopenflags()
. The documentation states:
To share symbols across extension modules, call as
sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL)
.
Here is the interpreter loading the extension with default settings:
>>> import myTest
>>> myTest.run()
/usr/bin/python: undefined symbol: target_func
And success occurs after modifying the interpreter's dlopen()
flags:
>>> import sys
>>> import dl
>>> sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL)
>>> import myTest
>>> myTest.run()
Works!