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

Stefan Seefeld stefan at seefeld.name
Fri Oct 24 13:12:39 CEST 2014


On 23/10/14 10:33 AM, Wintersberger, Eugen wrote:
> 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).

And why is that approach then not working for you ?

    Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list