views:

537

answers:

4
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

.Individully 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.

A: 

looks like you are linking statically compiled libs with a dll? msvcprtd.lib is a static library for the STL that is linked when tyou 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.

gbjbaanb
A: 

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).

xtofl
A: 

Use either dynamic or static linked runtime libraries:

LIBCPMTD.LIB - Multithreaded, static link

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

noonex
A: 

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.

Jamie Cook