Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
tools
vsnet.act
vsnet.debugging
vsnet.documentation
vsnet.enterprise.tools
vsnet.general
vsnet.ide
vsnet.jlca
vsnet.servicepacks
vsnet.setup
vsnet.vsip
vsnet.vss
vsnet.vstools.office
vstudio.development
vstudio.extensibility
vstudio.general
vstudio.helpauthoring
vstudio.setup
vstudio.sourcesafe
  
 
date: Wed, 23 Jul 2008 18:44:47 -0700 (PDT),    group: microsoft.public.vstudio.general        back       


multiple symbol linker issue w/VC++ 2005   
I have been programming C++ for years, but mostly with other tools.  I
do not recall encountering this issue, e.g. with Borland's C++ Builder
or with gcc.

I was surprised today to encounter multiple symbol definitions at link
time because I happened to use <iostream> in multiple compilation
units.  I found a way to get around it, but I am not happy with it.
It seems silly to me.  I use <iosfwd> in the headers, and <iostream>
in the corresponding compilation units, to provide an overload to the
output operator for each of a number of classes; and this error
strikes.  I used the /force option for the linker, so now it compiles;
a compromise for me since I know the symbols are identical, from the
same source code, but I tend to regard all warnings as obscenities to
be purged from my code as vigorously as errors (indeed, my preference
is to pass my code through a number of tools, to take advantage of the
differing strengths of different tool chains, and mitigate their
weaknesses).

It seems odd that VC++ 2005 would have a problem with this one part of
the standard library.

Is there a way to avoid such an issue without using /force (and the
concommitant transformation of the linker error into a warning)?

Thanks

Ted
date: Wed, 23 Jul 2008 18:44:47 -0700 (PDT)   author:   Ted Byers

Re: multiple symbol linker issue w/VC++ 2005   
Ted Byers wrote:
> I have been programming C++ for years, but mostly with other tools.  I
> do not recall encountering this issue, e.g. with Borland's C++ Builder
> or with gcc.
> 
> I was surprised today to encounter multiple symbol definitions at link
> time because I happened to use <iostream> in multiple compilation
> units.  I found a way to get around it, but I am not happy with it.
> It seems silly to me.  I use <iosfwd> in the headers, and <iostream>
> in the corresponding compilation units, to provide an overload to the
> output operator for each of a number of classes; and this error
> strikes.  I used the /force option for the linker, so now it compiles;
> a compromise for me since I know the symbols are identical, from the
> same source code, but I tend to regard all warnings as obscenities to
> be purged from my code as vigorously as errors (indeed, my preference
> is to pass my code through a number of tools, to take advantage of the
> differing strengths of different tool chains, and mitigate their
> weaknesses).
> 
> It seems odd that VC++ 2005 would have a problem with this one part of
> the standard library.
> 
> Is there a way to avoid such an issue without using /force (and the
> concommitant transformation of the linker error into a warning)?

Ted:

One of the Visual C++ groups would be better for this question.

This should not be happening. What do the linker errors say exactly?

-- 
David Wilkinson
Visual C++ MVP
date: Wed, 23 Jul 2008 22:00:34 -0400   author:   David Wilkinson

Re: multiple symbol linker issue w/VC++ 2005   
On Jul 23, 10:00 pm, David Wilkinson  wrote:
> Ted Byers wrote:
> > I have been programming C for years, but mostly with other tools.  I
> > do not recall encountering this issue, e.g. with Borland's C Builder
> > or with gcc.
>
> > I was surprised today to encounter multiple symbol definitions at link
> > time because I happened to use <iostream> in multiple compilation
> > units.  I found a way to get around it, but I am not happy with it.
> > It seems silly to me.  I use <iosfwd> in the headers, and <iostream>
> > in the corresponding compilation units, to provide an overload to the
> > output operator for each of a number of classes; and this error
> > strikes.  I used the /force option for the linker, so now it compiles> > a compromise for me since I know the symbols are identical, from the
> > same source code, but I tend to regard all warnings as obscenities to
> > be purged from my code as vigorously as errors (indeed, my preference
> > is to pass my code through a number of tools, to take advantage of the
> > differing strengths of different tool chains, and mitigate their
> > weaknesses).
>
> > It seems odd that VC 2005 would have a problem with this one part of
> > the standard library.
>
> > Is there a way to avoid such an issue without using /force (and the
> > concommitant transformation of the linker error into a warning)?
>
> Ted:
>
> One of the Visual C groups would be better for this question.
>
> This should not be happening. What do the linker errors say exactly?
>
> --
> David Wilkinson
> Visual C MVP- Hide quoted text -
>
> - Show quoted text -

Hi David

The first is:

Error	3	error LNK2005: "class std::basic_ostream<char,struct
std::char_traits<char> > & __cdecl operator<<(class
std::basic_ostream<char,struct std::char_traits<char> > &,class
investment_holding const &)" (??6@YAAAV?$basic_ostream@DU?
$char_traits@D@std@@@std@@AAV01@ABVinvestment_holding@@@Z) already
defined in MemoryBasedPortfolio.obj	portfolio_snapshot.obj


The second is:

Error	4	error LNK2005: "class std::basic_ostream<char,struct
std::char_traits<char> > & __cdecl operator<<(class
std::basic_ostream<char,struct std::char_traits<char> > &,class
investment_holding const &)" (??6@YAAAV?$basic_ostream@DU?
$char_traits@D@std@@@std@@AAV01@ABVinvestment_holding@@@Z) already
defined in MemoryBasedPortfolio.obj	portfolio.obj

And of course these are followed by:

Error	5	fatal error LNK1169: one or more multiply defined symbols
found	K:\MSVSProjects\MemoryBasedPortfolio\Debug
\MemoryBasedPortfolio.exe	1


The investment_holding compilation unit has an operator<<, as do a
couple others that happen to contain a container (usually an STL set)
of investment_holding instances.

Any ideas?

I can show you the operator<<() overloads, if that would help.

Thanks

Ted
date: Wed, 23 Jul 2008 19:27:39 -0700 (PDT)   author:   Ted Byers

Re: multiple symbol linker issue w/VC++ 2005   
Ted Byers wrote:
> On Jul 23, 10:00�pm, David Wilkinson  wrote:
>> Ted Byers wrote:
>>> I have been programming C++ for years, but mostly with other tools. �I
>>> do not recall encountering this issue, e.g. with Borland's C++ Builder
>>> or with gcc.
>>> I was surprised today to encounter multiple symbol definitions at link
>>> time because I happened to use <iostream> in multiple compilation
>>> units. �I found a way to get around it, but I am not happy with it.
>>> It seems silly to me. �I use <iosfwd> in the headers, and <iostream>
>>> in the corresponding compilation units, to provide an overload to the
>>> output operator for each of a number of classes; and this error
>>> strikes. �I used the /force option for the linker, so now it compiles;
>>> a compromise for me since I know the symbols are identical, from the
>>> same source code, but I tend to regard all warnings as obscenities to
>>> be purged from my code as vigorously as errors (indeed, my preference
>>> is to pass my code through a number of tools, to take advantage of the
>>> differing strengths of different tool chains, and mitigate their
>>> weaknesses).
>>> It seems odd that VC++ 2005 would have a problem with this one part of
>>> the standard library.
>>> Is there a way to avoid such an issue without using /force (and the
>>> concommitant transformation of the linker error into a warning)?
>> Ted:
>>
>> One of the Visual C++ groups would be better for this question.
>>
>> This should not be happening. What do the linker errors say exactly?
>>
>> --
>> David Wilkinson
>> Visual C++ MVP- Hide quoted text -
>>
>> - Show quoted text -
> 
> Hi David
> 
> The first is:
> 
> Error	3	error LNK2005: "class std::basic_ostream<char,struct
> std::char_traits<char> > & __cdecl operator<<(class
> std::basic_ostream<char,struct std::char_traits<char> > &,class
> investment_holding const &)" (??6@YAAAV?$basic_ostream@DU?
> $char_traits@D@std@@@std@@AAV01@ABVinvestment_holding@@@Z) already
> defined in MemoryBasedPortfolio.obj	portfolio_snapshot.obj
> 
> 
> The second is:
> 
> Error	4	error LNK2005: "class std::basic_ostream<char,struct
> std::char_traits<char> > & __cdecl operator<<(class
> std::basic_ostream<char,struct std::char_traits<char> > &,class
> investment_holding const &)" (??6@YAAAV?$basic_ostream@DU?
> $char_traits@D@std@@@std@@AAV01@ABVinvestment_holding@@@Z) already
> defined in MemoryBasedPortfolio.obj	portfolio.obj
> 
> And of course these are followed by:
> 
> Error	5	fatal error LNK1169: one or more multiply defined symbols
> found	K:\MSVSProjects\MemoryBasedPortfolio\Debug
> \MemoryBasedPortfolio.exe	1
> 
> 
> The investment_holding compilation unit has an operator<<, as do a
> couple others that happen to contain a container (usually an STL set)
> of investment_holding instances.
> 
> Any ideas?
> 
> I can show you the operator<<() overloads, if that would help.
> 
> Thanks

Ted:

These errors have to do with your own code, so it is "premature" to blame the 
compiler.

If these operator <<'s are defined in the header file but not inside the class 
definition, then they must be declared inline, or moved to the implementation file.

-- 
David Wilkinson
Visual C++ MVP
date: Thu, 24 Jul 2008 06:14:14 -0400   author:   David Wilkinson

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us