[Insight-developers] Multiple defined symbols : ifstream/ofstream : Examples/OperatingRoom

Luis Ibanez ibanez@choroid.cs.unc.edu
Mon, 24 Sep 2001 22:56:48 -0400 (EDT)


When std::ifstream and std::ofstream are used directly
the problem is similar. In fact, that's how it was originaly.
The typedefs were an attempt for localizing the instantiation
in only one place.

It seems that with multiple symbols defined the linker only
complains about the first collision found, and that's why
only liSpineModel.o appears on the message.


Now...from the repository,
it seems that Jim already found a solution by moving
<fstream> to be the first included header in the .cxx
that use it.

It is not clear to me why that fixes the problem, but
for sure the usual suspect should be the include of
"itkWindows.h",...

Luis


----------------------


On Mon, 24 Sep 2001, William A. Hoffman wrote:

> I don't think that is it.
>
> The linker is only complaining about the one in liSplineModel.obj, none of
> the other cxx files have the
> problem.  What happens if you don't have the typedef, but rather use
> std::ofstream directly?
> I think this is the only place with a typedef.  The other problem could be
> some other library
> #include'ing the old style fstream.h file??
>
> -Bill
>
>
> At 09:41 PM 9/24/2001 -0400, Luis Ibanez wrote:
>
>
>
> >It seems that what is different in this program is the fact
> >that is has multiple .cxx files and uses std::ifstream and
> >std::ofstream in several of them.
> >
> >
> >
> >The program uses the following hierarchy:
> >
> >
> >
> >
> >         itk::LightObject      fltk::GlDrawer
> >              ^                      ^
> >              |                      |
> >              |                      |
> >              +----------+-----------+
> >                         |
> >                         |
> >                    li::Shape3D
> >                         ^
> >                         |
> >                         |
> >        +----------------+----------------+-------------+....
> >        |                |                |                other
> >        |                |                |                classes(*)
> >  li::SpineModel    li::Tube3D     li::VectorTubes3D
> >
> >
> >
> >(*)  li::Tube3D
> >      li::VertebralSegment
> >      li::VertebralBody
> >      li::VertebralPedicle
> >      ...
> >      up to 21 classes.
> >
> >
> >
> >
> >Among them, only the following classes use fstreams:
> >
> >
> >
> >1)  li::Shape has the following typedefs:
> >
> >     typedef   ::std::ifstream     IfstreamType;
> >     typedef   ::std::ofstream     OfstreamType;
> >
> >     and doesn't use these types in any of its methods.
> >
> >
> >2)  li::SpineModel has read and write methods:
> >
> >      void Read( Shape3D::Ifstream & is );
> >      void Write( Shape3D::Ofstream & os, int level );
> >
> >
> >3)  li::VectorTubes3D has only a read method:
> >
> >      void Read( Shape3D::Ifstream & is );
> >
> >      and has an aggregate:
> >
> >      std::vector< li::Tube3D::Pointer >  m_Tubes;
> >
> >
> >
> >4)  li::Tube3D has only a Read() method:
> >
> >     void Read( Shape3D::Ifstream & is );
> >
> >
> >
> >5)  li::VertebralSegment has Read and Write methods:
> >
> >      void Read( Shape3D::Ifstream & is );
> >      void Write( Shape3D::Ofstream & os, int level );
> >
> >
> >
> >6)  li::VertebralBody has Read and Write methods:
> >
> >      void Read( Shape3D::Ifstream & is );
> >      void Write( Shape3D::Ofstream & os, int level );
> >
> >
> >
> >7)  li::VertebralPedicle has Read and Write methods:
> >
> >      void Read( Shape3D::Ifstream & is );
> >      void Write( Shape3D::Ofstream & os, int level );
> >
> >
> >
> >
> >When we remove liSpineModel, we got similar error messages but
> >this time complaining about duplicate symbols in liVectorTubes3D.o
> >and if we remove liVectorTubes3D the error message moves to another
> >class...
> >
> >
> >The problem seems to be related with the multiple instantiations
> >of std::ifstream and std::ofstream. That could be the reason why
> >this problem doesn't shows up in the rest of the tests.
> >
> >
> >   Any suggestions ?
> >
> >   Thanks
> >
> >   Luis
> >
> >
> >=======================================================================
> >
> >Bill Hoffman wrote:
> > >
> > > msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: void __thiscall
> > std::basic_ofstream<char,struct std::char_traits<char> >::`vbase
> > > destructor'(void)"
> > (??_D?$basic_ofstream@DU?$char_traits@D@std@@@std@@QAEXXZ) already
> > defined in liSpineModel.obj
> > > msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: void __thiscall
> > std::basic_ifstream<char,struct std::char_traits<char> >::`vbase
> > destructor'(void)"
> > > (??_D?$basic_ifstream@DU?$char_traits@D@std@@@std@@QAEXXZ) already
> > defined in liSpineModel.obj
> >
> >
> > > That error is saying that the ofstream destructor is defined in
> > msvcprt.lib and
> > > liSplineModel.obj.
> >
> > > So it is a conflict with the standard library and liSplineModel.obj.
> > > However, we use ostream stuff in other places in Insight with no problem.
> > > What is different about liSplineModel ?
> > >
> > >
>
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
>

-- 
Luis Ibanez                                      CB#:   7060
Research Assistan Professor                      phone: (919) 843 5436
Division of Neurosurgery                         fax:   (919) 966 6627
University of North Carolina at Chapel Hill      email: ibanez@cs.unc.edu
Chapel Hill, NC 27599-7060                       http://www.cs.unc.edu/~ibanez