[fdo-internals] dynamic_cast and shared libraries on Linux

Frank Warmerdam warmerdam at pobox.com
Tue Feb 20 12:43:03 EST 2007


Folks,

In the GDAL unit tests I am seeing some dynamic_cast failures that are
quite frustrating.

In particular this error:

  """
  7) test: 17RfpTestBandConfig.testGetNullValue1 (F) line: 32
  RfpTestBandConfig?.h

      "Unhandled FdoException? in testGetNullValue1"
  """

  Seems to be due to this dynamic_cast failing:
          FdoPtr<FdoISelect> cmdSelect = dynamic_cast<FdoISelect*>(cmd);

  cmd is in fact suitable to dynamically cast to FdoISelect, but the actual
  class is related to FdoISelect somewhat indirectly (through several layers
  of dirivation and use of a template).  According to the following FAQ this
  can result in problems with dynamic cast operating across shared library
  boundaries with gcc 3.x (or later?):

    http://www.gnu.org/software/gcc/faq.html#dso

  Changing the code to a static_cast resolves the issue.  I wonder if we
  need to require a particular version of gcc, or perhaps that we need
  to pursue some of the build options mentioned in the FAQ (which are a
  bit esoteric).  I did quickly try changing the dlopen() in
  FdoConnectionManagerto use the _GLOBAL flag but that did not seem to
  have an effect.

Has anyone else observed this sort of problem?  Are the GDAL unit tests
passing for anyone out there on linux?  If so, what version of gcc
are you using?

For the time being I'm changing the unit tests to use static_cast on linux,
but this puts application code that uses dynamic_cast in substantial danger.

Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org



More information about the fdo-internals mailing list