C Extensions: calling across extensions
Martin v. Loewis
martin at v.loewis.de
Wed May 29 18:49:12 EDT 2002
Maxwell Sayles <sayles at cpsc.ucalgary.ca> writes:
> do i need to do special declarations for importing and exporting
> functions across shared objects for python extension modules? do i need
> to compile with a -l option?
In general, you can't share symbols across extension modules. You have
the following alternatives:
1. use sys.setdlopenflags (in Python 2.2) to set the flags to RTLD_GLOBAL.
Notice that this may cause other problems.
2. Create a shared library that contains the code shared across the
extension modules, and link both extension modules with the shared code.
3. Use the C API to call the code in A from B, just as if you would
call the code in A from any Python module.
4. Use the CObject to share a C-level API between A and B; see
cStringIO.c for an example (cStringIO_CAPI).
HTH,
Martin
More information about the Python-list
mailing list