Cute
Cute

Reputation: 14011

How to resolve Link error 2005 in Visual Studio?

error LNK2005: "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::basic_ostream<char,struct std::char_traits<char> >(class std::basic_streambuf<char,struct std::char_traits<char> > *,bool)" (??0?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@PAV?$basic_streambuf@DU?$char_traits
@D@std@@@1@_N@Z) already defined in msvcprtd.lib(MSVCP80D.dll)  libcpmtd.lib

I am getting this error when i try to include /clr option and /MDd options in subproject.

Individually all the projects are building successfully but when I build main project it shows the above like errors.

How to resolve this one?

I am totally vexed.

Upvotes: 0

Views: 10753

Answers (5)

Bilal Ansar
Bilal Ansar

Reputation: 1

This error occur when we have same definition of two header files and use in main
This error will resolve when you have different variable and function names in both header files

Upvotes: 0

gbjbaanb
gbjbaanb

Reputation: 52679

It looks like you are linking statically compiled libs with a dll? msvcprtd.lib is a static library for the STL that is linked when you compile with /MDd.

Libcmptd.lib is a CRT library that gets used when you specify /MTd.

See here for which libs are used by which setting.

Check your build settings so they are all the same.

Upvotes: 0

Jamie Cook
Jamie Cook

Reputation: 4525

Make sure that all your individual projects are compiled with the same runtime libraries, this is specified in:

Properties -> C/C++ -> Code Generation -> Runtime Library

If you are using /MDd make sure that all other projects are too. Otherwise when you link them all together in the main project it will import multiple versions of the runtime libraries leading to the error you are observing.

Upvotes: 1

noonex
noonex

Reputation: 2075

Use either dynamic or static linked runtime libraries:

LIBCPMTD.LIB - Multithreaded, static link

MSVCPRTD.LIB - Multithreaded, dynamic link (import library for MSVCP80D.DLL)

Upvotes: 0

xtofl
xtofl

Reputation: 41509

The linker says he's seen that symbol defined in more than one object file / library.

Try to find out which ones do export it (e.g. using dumpbin), find out why (is some standard library linked in statically?) and if you need it.

For this specific case:

This operator is provided both inline (which causes your projects to define it) and as an export from the msvcprtd.dll. You can work around this by declaring the symbol as __declspec(dllimport).

Upvotes: 0

Related Questions