Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / July 2008

Tip: Looking for answers? Try searching our database.

multiple symbol linker issue w/VC++ 2005

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ted Byers - 24 Jul 2008 02:44 GMT
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
David Wilkinson - 24 Jul 2008 03:00 GMT
> 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
[quoted text clipped - 19 lines]
> 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?

Signature

David Wilkinson
Visual C++ MVP

Ted Byers - 24 Jul 2008 03:27 GMT
> > 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
[quoted text clipped - 31 lines]
>
> - 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
David Wilkinson - 24 Jul 2008 11:14 GMT
>>> 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
[quoted text clipped - 63 lines]
>
> 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.

Signature

David Wilkinson
Visual C++ MVP


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.