[Insight-users] Static compilation of itk in different dynamic libs

Mathieu Malaterre mathieu.malaterre at gmail.com
Tue May 25 11:03:24 EDT 2010


Hi Benoit,

  [Congrats on the new job]

On Tue, May 25, 2010 at 4:50 PM,  <Benoit.Bleuze at sophia.inria.fr> wrote:
> Hi all,
>
> I am experiencing some problems with the static linking of itk and the use
> of the included gdcm.
>
> Let's compile a static itk, then include it in 2 different libraries, in my
> case they are then dynamically linked to a other third one in which resides
> the executable. Call them libA and libB. Both use an itkImageIOFactory at
> some point.
>
> They work fine, until the application closes, and the program tries to
> delete the gdcm::Global object internally used by the itkGDCMImageIOFactory
> object which is created at instanciation time.
>
> The fact that the libraries A and B are not aware of one an other results in
> the fact that gdcm::Global is created two times, but the constructor
> allocates the memory only once for the class variables in Global. Obviously
> this crashes. This breaks the singleton pattern and I expected an unexpected
> result. Is there a way to handle that situation in itk? For instance, is
> there at least a way to not instanciate the gdcm factory along with the
> others? We don't use gdcm to deal with dicom images, and therefore woudn't
> mind getting rid of this factory.
>
> Additional question: are there any other singleton classes that may behave
> the same way and get me in trouble even further?

Your problem seems extremely easy to reproduce. Could you please
prepare a small cmakelists project that I can use to reproduce the
issue with ?
I did -shamelessly- copy the design of the gdcm singleton from vtk. I
believe the init / finalize of the class are working properly.

By any chance are you using a MSVC compiler (I am thinking of a bug
that only occur in Release build).

Thanks,
-- 
Mathieu


More information about the Insight-users mailing list