[C++-sig] Cross-module inheritance

David Abrahams dave at boost-consulting.com
Sun Aug 21 17:25:29 CEST 2005

Eric Jardim <ericjardim at gmail.com> writes:

> Hi again,
> I searched google and discovered that the problem is
> real. Cross-module inheritance and some other things do not work
> with boost.python (I don't know why).

It certainly does work; you just have to follow some rules when you
build your extensions to make sure their RTTI info is properly shared.

> Some old posts show it:
> http://lists.boost.org/Archives/boost/2001/07/14520.php
> http://lists.boost.org/Archives/boost/2001/07/14491.php

That was for Boost.Python v1.  You are (I hope) using the improved
Boost.Python v2

> And recent posts show that some guys resolved the problem (partially):
> http://mail.python.org/pipermail/c++-sig/2005-April/008829.html
> http://mail.python.org/pipermail/c++-sig/2005-April/008835.html
> Doing:
> import sys, dl
> sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)

This is the brute-force method.  A more delicate and portable approach
is to stick the common base class in a shared library that is linked
to by all the extension modules that derive from it.

> But, I am afraid this is not a portable solution. 
> 1 - Could anyone tell me if, at least, this solution is portable among gcc 
> compilation, even on Windows?

No, the Windows dynamic linking system is different.  However, the
approach I suggested above works fine.

> 2 - Does anyone suggest me to use this trick now, or should I stay with the 
> "single-module", and wait for this issue to be solved (is it possible, given 
> boost.python current state?)

There is no "solving it" further; it has nothing to do with the state
of Boost.Python.  It has to do with the way shared libraries and
run-time type information work on your platform.

> 3 - Is there any other workaround? It looks like SWIG can do it (am I 
> right?)
> 4 - Should I give up everything? ( hope not ;) 

It's a little early for that yet.

Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list