thrust library linking errors msvcprt.lib(MSVCP90.dll) : error LNK2005

I am using the thrust library in CUDA 4.0. Basically I want to use it to replace CUDPP. When I tried to add

int h_sum = thrust::reduce(dev_ptr_out, dev_ptr_out + array_size, 0, thrust::plus<float>());

to my current project, it has no problem in compiling, but it has linking errors as below:

1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in main.cu.obj

1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::operator=(char const *)" (??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z) already defined in main.cu.obj

1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in main.cu.obj

1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in main.cu.obj

1>msvcprt.lib(MSVCP90.dll) : error LNK2005: "public: static unsigned int __cdecl std::char_traits<char>::length(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in main.cu.obj

How to handle this linking problem? Thank you,

I am getting the same link errors since I try to compile with cuda 4.0

I don’t know if it is especially related to thrust, but I am also using thrust.

Note that the runtime libraries are correctly given in both cpp and cuda compilation.

Please help, I have already lost too much time on it and nothing is working anymore…

– pium

edit: I confirm that the error is linked to thrust (by commenting every stuff relative to thrust it compiles/links/works)
edit2: just including a header file from thrust (without using any function) creates the error

In the SDK, the marching cube example is using thrust and is compiling.

By default, this project is using static runtime libraries /MT
A soon as I compiles with dynamic runtime libraries /MD, I obtain a bunch of warnings C4251 relatives to std::basic_string and the same linking errors…
(since I am using compiled libraries that link dynamically I have no choice on this option)

I am stopping to post msg here, but I am going on the thrust bugtracker… :(

Let me answer the question myself in case it is useful.

  1. change the CPP option from /MD to /MT
  2. previously I chose to ignore libcmt.lib; now I should not ignore it any more: just remove it from the ignore list.

Well, you can avoid the error that way, but it does not really fix the issue in a long term. After all, maybe someone wants to build using multithreaded DLLs… ;-)

What is your solution if we have to use /MD?

Despair. There is another thread bumping around (found here) regarding that topic. It appears to be a problem in the NVCC compiler, but so far nobody has found a solution… For the time being, /MT seems to be the only viable option. Of course, maybe we all just overlooked something obvious…

the new cudafe++ seems to be buggy; the one from SDK 3.2 can also be used for 4.0. Just copy to the appropriate directory.

I can repro this with the Marching cubes example and 4.0 RC2



Add the following below to marchingCubes.cpp at line 71 (the #ifdef _WIN32 section):



#include <iostream>



And the following at line 356 (in main):



std::cout << "test" << std::endl;



Rebuild and see the following:



1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ) already defined in marchingCubes_kernel.cu.obj

1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const ,__int64)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAE_JPBD_J@Z) already defined in marchingCubes_kernel.cu.obj

1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in marchingCubes_kernel.cu.obj

1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in marchingCubes_kernel.cu.obj

1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHD@Z) already defined in marchingCubes_kernel.cu.obj

1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in marchingCubes_kernel.cu.obj

1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > & (__cdecl
)(class std::basic_ostream<char,struct std::char_traits<char> > &))" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z) already defined in marchingCubes_kernel.cu.obj

1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in marchingCubes_kernel.cu.obj

1>msvcprt.lib(MSVCP100.dll) : error LNK2005: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in marchingCubes_kernel.cu.obj

1>../../bin/win32/Release//marchingCubes.exe : fatal error LNK1169: one or more multiply defined symbols found

Hi,

I had similar issues with another code. Found out that defining _STATIC_CPPLIB in preprocessor symbols helps. I wonder if it helps here …

cheers!