[Insight-developers] Multiple defined symbols : ifstream/of
stream : Examples/OperatingRoom
Miller, James V (CRD)
millerjv@crd.ge.com
Tue, 25 Sep 2001 09:39:41 -0400
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C145C7.87139320
Content-Type: text/plain
I fixed this problem last night. I moved the #include <fstream> lines from the cxx files to the
header files. Furthermore, I made fstream the first include file in each of the files that used
fstreams.
The offending classes had methods that took "ofstream &" or "ifstream &". But ifstream and ofstream
were not forwardly declared. My best guess is that one of the other include files were including
the "old" streams. So incompatible stream "libraries" were being linked together.
Putting <fstream> as the first include file in each *.h file fixed this problem.
-----Original Message-----
From: Luis Ibanez [ mailto:ibanez@choroid.cs.unc.edu <mailto:ibanez@choroid.cs.unc.edu> ]
Sent: Monday, September 24, 2001 10:57 PM
To: William A. Hoffman
Cc: insight-Developers
Subject: Re: [Insight-developers] Multiple defined symbols :
ifstream/ofstream : Examples/OperatingRoom
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
<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
<http://www.cs.unc.edu/~ibanez>
_______________________________________________
Insight-developers mailing list
Insight-developers@public.kitware.com
http://public.kitware.com/mailman/listinfo/insight-developers
<http://public.kitware.com/mailman/listinfo/insight-developers>
------_=_NextPart_001_01C145C7.87139320
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE></TITLE>
<META content="MSHTML 5.50.4616.200" name=GENERATOR></HEAD>
<BODY>
<P><FONT size=2>I fixed this problem last night. I moved the #include
<fstream> lines from the cxx files to the header files. Furthermore,
I made fstream the first include file in each of the files that used
fstreams.</FONT></P>
<P><FONT size=2><FONT color=#0000ff>The offending classes had methods that took
"ofstream &" or "ifstream &". But ifstream and ofstream were not
forwardly declared. My best guess is that one of the other include files
were including the "old" streams. So incompatible stream "libraries"
were being linked together.</FONT></FONT></P>
<P><FONT size=2><FONT color=#0000ff>Putting <fstream> as the first include
file in each *.h file fixed this problem.</FONT></P>
<P><BR><BR>-----Original Message-----<BR>From: Luis Ibanez [<A
href="mailto:ibanez@choroid.cs.unc.edu">mailto:ibanez@choroid.cs.unc.edu</A>]<BR>Sent:
Monday, September 24, 2001 10:57 PM<BR>To: William A. Hoffman<BR>Cc:
insight-Developers<BR>Subject: Re: [Insight-developers] Multiple defined symbols
:<BR>ifstream/ofstream : Examples/OperatingRoom<BR><BR><BR><BR><BR>When
std::ifstream and std::ofstream are used directly<BR>the problem is similar. In
fact, that's how it was originaly.<BR>The typedefs were an attempt for
localizing the instantiation<BR>in only one place.<BR><BR>It seems that with
multiple symbols defined the linker only<BR>complains about the first collision
found, and that's why<BR>only liSpineModel.o appears on the
message.<BR><BR><BR>Now...from the repository,<BR>it seems that Jim already
found a solution by moving<BR><fstream> to be the first included header in
the .cxx<BR>that use it.<BR><BR>It is not clear to me why that fixes the
problem, but<BR>for sure the usual suspect should be the include
of<BR>"itkWindows.h",...<BR><BR>Luis<BR><BR><BR>----------------------<BR><BR><BR>On
Mon, 24 Sep 2001, William A. Hoffman wrote:<BR><BR>> I don't think that is
it.<BR>><BR>> The linker is only complaining about the one in
liSplineModel.obj, none of<BR>> the other cxx files have the<BR>>
problem. What happens if you don't have the typedef, but rather
use<BR>> std::ofstream directly?<BR>> I think this is the only place with
a typedef. The other problem could be<BR>> some other library<BR>>
#include'ing the old style fstream.h file??<BR>><BR>>
-Bill<BR>><BR>><BR>> At 09:41 PM 9/24/2001 -0400, Luis Ibanez
wrote:<BR>><BR>><BR>><BR>> >It seems that what is different in
this program is the fact<BR>> >that is has multiple .cxx files and uses
std::ifstream and<BR>> >std::ofstream in several of them.<BR>>
><BR>> ><BR>> ><BR>> >The program uses the following
hierarchy:<BR>> ><BR>> ><BR>> ><BR>> ><BR>>
>
itk::LightObject fltk::GlDrawer<BR>>
>
^
^<BR>>
>
|
|<BR>>
>
|
|<BR>>
>
+----------+-----------+<BR>>
>
|<BR>>
>
|<BR>>
>
li::Shape3D<BR>>
>
^<BR>>
>
|<BR>>
>
|<BR>> >
+----------------+----------------+-------------+....<BR>>
>
|
|
|
other<BR>> >
|
|
|
classes(*)<BR>> > li::SpineModel
li::Tube3D li::VectorTubes3D<BR>> ><BR>>
><BR>> ><BR>> >(*) li::Tube3D<BR>>
> li::VertebralSegment<BR>>
> li::VertebralBody<BR>>
> li::VertebralPedicle<BR>>
> ...<BR>>
> up to 21 classes.<BR>> ><BR>>
><BR>> ><BR>> ><BR>> >Among them, only the following
classes use fstreams:<BR>> ><BR>> ><BR>> ><BR>>
>1) li::Shape has the following typedefs:<BR>> ><BR>>
> typedef
::std::ifstream IfstreamType;<BR>>
> typedef
::std::ofstream OfstreamType;<BR>> ><BR>>
> and doesn't use these types in any of its
methods.<BR>> ><BR>> ><BR>> >2) li::SpineModel has read
and write methods:<BR>> ><BR>> > void
Read( Shape3D::Ifstream & is );<BR>> >
void Write( Shape3D::Ofstream & os, int level );<BR>> ><BR>>
><BR>> >3) li::VectorTubes3D has only a read method:<BR>>
><BR>> > void Read( Shape3D::Ifstream
& is );<BR>> ><BR>> > and has an
aggregate:<BR>> ><BR>> >
std::vector< li::Tube3D::Pointer > m_Tubes;<BR>> ><BR>>
><BR>> ><BR>> >4) li::Tube3D has only a Read()
method:<BR>> ><BR>> > void Read(
Shape3D::Ifstream & is );<BR>> ><BR>> ><BR>> ><BR>>
>5) li::VertebralSegment has Read and Write methods:<BR>>
><BR>> > void Read( Shape3D::Ifstream
& is );<BR>> > void Write(
Shape3D::Ofstream & os, int level );<BR>> ><BR>> ><BR>>
><BR>> >6) li::VertebralBody has Read and Write methods:<BR>>
><BR>> > void Read( Shape3D::Ifstream
& is );<BR>> > void Write(
Shape3D::Ofstream & os, int level );<BR>> ><BR>> ><BR>>
><BR>> >7) li::VertebralPedicle has Read and Write
methods:<BR>> ><BR>> > void Read(
Shape3D::Ifstream & is );<BR>> > void
Write( Shape3D::Ofstream & os, int level );<BR>> ><BR>>
><BR>> ><BR>> ><BR>> >When we remove liSpineModel, we got
similar error messages but<BR>> >this time complaining about duplicate
symbols in liVectorTubes3D.o<BR>> >and if we remove liVectorTubes3D the
error message moves to another<BR>> >class...<BR>> ><BR>>
><BR>> >The problem seems to be related with the multiple
instantiations<BR>> >of std::ifstream and std::ofstream. That could be the
reason why<BR>> >this problem doesn't shows up in the rest of the
tests.<BR>> ><BR>> ><BR>> > Any suggestions
?<BR>> ><BR>> > Thanks<BR>> ><BR>>
> Luis<BR>> ><BR>> ><BR>>
>=======================================================================<BR>>
><BR>> >Bill Hoffman wrote:<BR>> > ><BR>> > >
msvcprt.lib(MSVCP60.dll) : error LNK2005: "public: void __thiscall<BR>> >
std::basic_ofstream<char,struct std::char_traits<char>
>::`vbase<BR>> > > destructor'(void)"<BR>> >
(??_D?$basic_ofstream@DU?$char_traits@D@std@@@std@@QAEXXZ) already<BR>> >
defined in liSpineModel.obj<BR>> > > msvcprt.lib(MSVCP60.dll) : error
LNK2005: "public: void __thiscall<BR>> >
std::basic_ifstream<char,struct std::char_traits<char>
>::`vbase<BR>> > destructor'(void)"<BR>> > >
(??_D?$basic_ifstream@DU?$char_traits@D@std@@@std@@QAEXXZ) already<BR>> >
defined in liSpineModel.obj<BR>> ><BR>> ><BR>> > > That
error is saying that the ofstream destructor is defined in<BR>> >
msvcprt.lib and<BR>> > > liSplineModel.obj.<BR>> ><BR>> >
> So it is a conflict with the standard library and
liSplineModel.obj.<BR>> > > However, we use ostream stuff in other
places in Insight with no problem.<BR>> > > What is different about
liSplineModel ?<BR>> > ><BR>> > ><BR>><BR>>
_______________________________________________<BR>> Insight-developers
mailing list<BR>> Insight-developers@public.kitware.com<BR>> <A
target=_blank
href="http://public.kitware.com/mailman/listinfo/insight-developers">http://public.kitware.com/mailman/listinfo/insight-developers</A><BR>><BR><BR>--<BR>Luis
Ibanez
CB#: 7060<BR>Research Assistan
Professor
phone: (919) 843 5436<BR>Division of
Neurosurgery
fax: (919) 966 6627<BR>University of North Carolina at Chapel
Hill email: ibanez@cs.unc.edu<BR>Chapel Hill, NC
27599-7060
<A target=_blank
href="http://www.cs.unc.edu/~ibanez">http://www.cs.unc.edu/~ibanez</A><BR><BR><BR>_______________________________________________<BR>Insight-developers
mailing list<BR>Insight-developers@public.kitware.com<BR><A target=_blank
href="http://public.kitware.com/mailman/listinfo/insight-developers">http://public.kitware.com/mailman/listinfo/insight-developers</A><BR></P></FONT></BODY></HTML>
------_=_NextPart_001_01C145C7.87139320--