error LNK2005 When using <iostream> in .cu file I'm getting an error of duplicate symbol

I am trying to build a CUDA project under VS2010. I have the following files

main.cpp <- main program

kernel.cu <- file containg kernels

Inside kernel.cu file theres a wrapper function for the kernel, and some prints are done in this function using cout, clog and cerr. is included both in main.cpp and kernel.cu and I’m getting the following errors

msvcprtd.lib(MSVCP100D.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 teste.cu.obj

1>msvcprtd.lib(MSVCP100D.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 teste.cu.obj

...

and so on

I was able to realize that this error means that the symbols of are duplicated. In fact they are, one time compiled using vc100 and another time using nvcc. I was able to solve this problem changing the output form of nvcc to -cubin instead of -compile.

I was wondering what is the main difference between these options.

Does -compile flag makes nvcc to link the code on .cu files and -cubin generates the cuda obj files?

This seems to be a general problem. See here also: http://forums.nvidia.com/index.php?showtopic=194944&st=0&p=1232033&#entry1232033

Some of the samples also have the same issue. The nbody sample doesn’t seem to compile for 4.0 RC2 for example.

That’s right. NBody did not compile in my machine