Mark Sienkiewicz <sienk...@stsci.edu> writes: > Compile a C extension that requires a shared library that is not in the > standard system path. To import it, LD_LIBRARY_PATH needs to be right.
I just discovered, in the course of repairing my "pyzmq-static" project after the "pyzmq" folks went crazy and broke their single extension module into a dozen modules, that there is another alternative to the LD_LIBRARY_PATH environment variable. If an extension wants to build and use a .so shared library, then the Python package can build and install the library somewhere beneath the package's main directory, then the package can preload the library manually as the first thing __init__.py does, by writing code like this: import ctypes import os p = os.path.join(os.path.dirname(__file__), "mylibrary.so") _library = ctypes.CDLL(p, mode=ctypes.RTLD_GLOBAL) Because the RTLD_GLOBAL mode makes all of the symbols in "mylibrary.so" available to subsequently-loaded shared object files, any subsequent import of a dynamically linked Python extension should link its symbols against "mylibrary.so" just fine without a need to set LD_LIBRARY_PATH. -- Brandon Craig Rhodes bran...@rhodesmill.org http://rhodesmill.org/brandon _______________________________________________ Distutils-SIG maillist - Distutils-SIG@python.org http://mail.python.org/mailman/listinfo/distutils-sig