[C++-sig] Dynamic Cast failed over multiple modules

Holger Brandsmeier brandsmeier at gmx.de
Thu Sep 8 11:56:23 CEST 2011


Dear List,

when I use dynamic cast from two boost modules on a class with "vague
linkage", in my real use case a template in the simplified example I
show you a class which is declared inline, then the dynamic cast fails
in the second module.

So when I call the code from python from the first module (in which
the Vertex object has been created), then the dynamic cast succeeds:

"calling performTest(m) ...
I am a Vertex"

but when I do the same from the other module, then I get

"calling performTest2(m) ...
dynamic cast failed, I got the object:
I am a Vertex"

I attached a very simple example in the files:
  bugDynamicCastSimplified.h (declares the Classes VerboseObject,
Vertex and Mesh)
  bugDynamicCastPy.cpp (first boost module)
  bugDynamicCast2Py.cpp (second boost module)

The problem dissapears without the vague linkage, e.g. when you define
REMOVE_INLINE_DEFINITION in the code. This is not a very nice  option
for me, as in my real use case Vertex is a template, and this would
force me to initialize it for each type.

My gcc is:
> g++ --version
g++ (Gentoo 4.4.5 p1.2, pie-0.4.5) 4.4.5

And I am building the project with cmake (not boost). I read the FAQ
entry at http://gcc.gnu.org/faq.html#dso and added "-Wl,-E" to
CMAKE_SHARED_LINKER_FLAGS. About the RTLD_GLOBAL flag for dlopen, I
don't know how python handles this.

Do you have any ideas how to solve this? Or is this simply not
possible with python?

-Holger
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bugDynamicCastSimplified.h
Type: text/x-chdr
Size: 913 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20110908/8fffad6a/attachment.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bugDynamicCastPy.cpp
Type: text/x-c++src
Size: 250 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20110908/8fffad6a/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bugDynamicCast2Py.cpp
Type: text/x-c++src
Size: 213 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20110908/8fffad6a/attachment-0001.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bugDynamicCastSimplified.cpp
Type: text/x-c++src
Size: 154 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20110908/8fffad6a/attachment-0002.cpp>


More information about the Cplusplus-sig mailing list