Cannot use STD namespace in my cuda files

Hello,

Im having a problem to use std::cout << in my cuda file

Im new to c++ , so the problem might actually be ver easy

im using
#include

and the erros im getting are manyfold

(But only if i use the std::cout)

1>libcpmt.lib(xmutex.obj) : error LNK2005: “public: void __cdecl std::_Mutex::_Lock(void)” (?_Lock@_Mutex@std@@QEAAXXZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>libcpmt.lib(xmutex.obj) : error LNK2005: “public: void __cdecl std::_Mutex::_Unlock(void)” (?_Unlock@_Mutex@std@@QEAAXXZ) already defined in msvcprtd.lib(MSVCP90D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: “public: __cdecl std::exception::exception(void)” (??0exception@std@@QEAA@XZ) already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: “public: __cdecl std::exception::exception(char const * const &)” (??0exception@std@@QEAA@AEBQEBD@Z) already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: “public: __cdecl std::exception::exception(class std::exception const &)” (??0exception@std@@QEAA@AEBV01@@Z) already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: “public: virtual __cdecl std::exception::~exception(void)” (??1exception@std@@UEAA@XZ) already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(stdexcpt.obj) : error LNK2005: "public: virtual char const * __cdecl std::exception::what(void)const " (?what@exception@std@@UEBAPEBDXZ) already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(setlocal.obj) : error LNK2005: _configthreadlocale already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(_file.obj) : error LNK2005: __iob_func already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: _encode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: _decode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _amsg_exit already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _initterm_e already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: exit already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _cexit already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: _unlock already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: _lock already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(winxfltr.obj) : error LNK2005: _XcptFilter already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0.obj) : error LNK2005: mainCRTStartup already defined in MSVCRTD.lib(crtexe.obj)
1>LIBCMT.lib(errmode.obj) : error LNK2005: __set_app_type already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: __xi_a already defined in MSVCRTD.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: __xi_z already defined in MSVCRTD.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: __xc_a already defined in MSVCRTD.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: __xc_z already defined in MSVCRTD.lib(cinitexe.obj)
1>LIBCMT.lib(hooks.obj) : error LNK2005: “void __cdecl terminate(void)” (?terminate@@YAXXZ) already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LIBCMT.lib(getenv.obj) : error LNK2005: getenv already defined in MSVCRTD.lib(MSVCR90D.dll)
1>LINK : warning LNK4098: defaultlib ‘MSVCRTD’ conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib ‘LIBCMT’ conflicts with use of other libs; use /NODEFAULTLIB:library

can someone please help me?

What CUDA version are you using? I think 2.2 or 2.3 already enables you to use std in the .cu file…

eyal

im using 2.3!

Eas solution:

Refer to a cpp file and make your std things there

Perhaps it’s an issue of wrong runtime library. CUDA stuff is compiled with /MT (or /MTd for debug versions). Your linker errors suggest you’re trying to build at least some files with /MD.

Rightclick the .cu file, Properties -> Code generation -> Runtime Library