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

Stefan Seefeld stefan at seefeld.name
Thu Oct 23 15:50:11 CEST 2014


On 22/10/14 08:08 AM, Wintersberger, Eugen wrote:
> Hi there
>   I have a little problem with two Python extensions (C++ with
> boost::python) where share code. An example of what I am trying to do is
> attached to this mail so I will refer to the code in the tarball to
> explain the problem. 
>
> I have to Python extensions ('a' and 'b') each of them exporting two
> functions. What I want is to use a function exported by 'a' in the code
> of 'b'. Though the package compiles I get an unresolved symbol error
> when trying to load 'b'. 
>
> The reason is quite clear. 'b' cannot resolve the symbol as it is
> provided by 'a' to which it is not linked. Is it somehow possible with
> distutils to link the two extensions to that 'b' can see the symbols
> provided by 'a'?

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. 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'.

         Stefan



-- 

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



More information about the Cplusplus-sig mailing list