[C++-sig] dynamic linking in Linux

Jim Bosch talljimbo at gmail.com
Fri Jul 23 09:08:01 CEST 2010


I've just run into the "wontfix" problem detailed here:

https://svn.boost.org/trac/boost/ticket/3210

Essentially, shared information held in one module (such as RTTI stuff 
needed for dynamic cast) isn't available to another module, leading to 
segfaults.

I got the impression from reading the ticket comments and the linked 
email threads that the best solution is to do something like this, where 
module "B" depends on module "A":

liba.so ---- C++ objects for A and Boost.Python wrappers.

a.so ------- module, linked against liba.so, just invokes wrapper 
generator functions defined in liba.so within a BOOST_PYTHON_MODULE block.

libb.so ---- C++ objects for B and Boost.Python wrappers; linked against 
liba.so

b.so ------- module, linked against libb.so and liba.so, just invokes 
wrapper generator functions defined in libb.so within a 
BOOST_PYTHON_MODULE block


However, that's not working, and the only solution I've found is to put 
my modules in packages with something like the following in __init__.py:

import ctypes
ctypes.PyDLL("%s/_a" % tuple(__path__), ctypes.RTLD_GLOBAL)
from . import _a

Another similar option, using sys.setdlopenflags, seems to be less 
favored because the dl module needed to get the flags has been 
deprecated in Python itself.

Is this just the current state of things?  Are there any efforts 
underway to improve matters?  Or was I on track in the first case, and I 
was just doing it wrong?

Thanks!

Jim Bosch


More information about the Cplusplus-sig mailing list