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

William A. Hoffman bill.hoffman@kitware.com
Mon, 24 Sep 2001 22:06:41 -0400


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 ?
> >
> >