[C++-sig] sharing code between different python extensions

Wintersberger, Eugen eugen.wintersberger at desy.de
Thu Oct 23 16:33:48 CEST 2014


Hi Stefan
  
> Python extension modules may not depend on each other in that way.
> (Arguably that is a Good Thing, as it avoids possible ABI compatibility
> issues.)
> What I suggest you do is either refactor the code such that your
> extensions 'a' and 'b' both link to a shared library 'c' which provides
> the symbols used by both. 

If the real problem would be as in the example I would definitely go
with this approach (I even tried to do so). However, the real problem is
more complex. The functions in 'a' call Python API and numpy API
functions. Thus, when distutils builds the code it does this according
to a particular Python version. So building a single shared library
would not help too much. 

> Alternatively you could try to reduce the
> dependency to only exist at the Python interface level, such that using
> 'b' requires 'a' being loaded (for example to enable type converters
> defined in 'a' but used in 'b'), but without any direct ABI dependencies
> between 'a' and 'b'.

This is interesting as it is much closer to my real problem. Extension
'a' provides some converters from numpy objects to my own C++ types and
back. And these guys I would like to use in 'b' (along with some other
numpy utility functions). 

regards
  Eugen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 230 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20141023/a55d4967/attachment-0001.sig>


More information about the Cplusplus-sig mailing list