I am venturing into the land of creating C/C++ bindings for Python using pybindgen. I've followed the steps outlined under "Building it ( GCC instructions )" to create bindings for the sample files:
http://packages.python.org/PyBindGen/tutorial.html#a-simple-example
Running make
produces a .so file. If I understand how .so files work, I should be able to import
the classes in the shared object into Python. However, I'm not sure where to place the file and how to let Python know where it is. Additionally, do the original c/c++ source files need to accompany the .so file?
So far I've tried placing the file in /usr/local/lib and adding that path to DYLD_LIBRARY_PATH to the .bash_profile. When I try to import the module from within the Python interpeter an error is thrown stating that the module can not be found.
So, my question is: What needs to be done with the generated .so file in order for it to be used by a Python program?
Python looks for .so
modules in the same directories where it searches python ones. So you have to install it as you would normal python module either somewhere that is on python's sys.path
by default (/usr/share/python/site-lib
or something like that—it'd distribution-dependent) or add the directory to PYTHONPATH
environment variable.
It's python that's loading the module using dlopen, not the dynamic linker, so LD_LIBRARY_PATH
(note, there is no DY
) won't help you.