Cuda library in the C++ program

I want to create CUDA library in other program but found below errors:



It is further found that CUDA Program use only the library created by the Cuda Wizard.



If i tried to use the library (generatd by cuda) in c++ project then below error is coming:



Linking…

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __cdecl std::basic_ios >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QEAAXH_N@Z) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __int64 __cdecl std::ios_base::width(__int64)" (?width@ios_base@std@@QEAA_J_J@Z) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __int64 __cdecl std::basic_streambuf >::sputn(char const *,__int64)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAA_JPEBD_J@Z) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static bool __cdecl std::char_traits::eq_int_type(int const &,int const &)" (?eq_int_type@?$char_traits@D@std@@SA_NAEBH0@Z) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static int __cdecl std::char_traits::eof(void)" (?eof@?$char_traits@D@std@@SAHXZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __cdecl std::basic_streambuf >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAAHD@Z) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_streambuf > * __cdecl std::basic_ios >::rdbuf(void)const " (?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBAPEAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: char __cdecl std::basic_ios >::fill(void)const " (?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBADXZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: int __cdecl std::ios_base::flags(void)const " (?flags@ios_base@std@@QEBAHXZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: __int64 __cdecl std::ios_base::width(void)const " (?width@ios_base@std@@QEBA_JXZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: static unsigned __int64 __cdecl std::char_traits::length(char const )" (?length@?$char_traits@D@std@@SA_KPEBD@Z) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_ostream > & __cdecl std::basic_ostream >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAAEAV12@XZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::basic_ostream > * __cdecl std::basic_ios >::tie(void)const " (?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QEBAPEAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: bool __cdecl std::ios_base::good(void)const " (?good@ios_base@std@@QEBA_NXZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __cdecl std::basic_ostream >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QEAAXXZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __cdecl std::basic_streambuf >::_Lock(void)" (?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAAXXZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: void __cdecl std::basic_streambuf >::_Unlock(void)" (?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QEAAXXZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

msvcprtd.lib(MSVCP90D.dll) : error LNK2005: "public: class std::locale::facet * __cdecl std::locale::facet::_Decref(void)" (?_Decref@facet@locale@std@@QEAAPEAV123@XZ) already defined in cudalibcreation.lib(cudalibcreation.obj)

libcpmtd.lib(locale0.obj) : error LNK2005: "void __cdecl _AtModuleExit(void (__cdecl
)(void))" (?_AtModuleExit@@YAXP6AXXZ@Z) already defined in msvcprtd.lib(locale0_implib.obj)

libcpmtd.lib(locale0.obj) : error LNK2005: _Fac_tidy already defined in msvcprtd.lib(locale0_implib.obj)

libcpmtd.lib(locale0.obj) : error LNK2005: "private: static void __cdecl std::locale::facet::facet_Register(class std::locale::facet *)" (?facet_Register@facet@locale@std@@CAXPEAV123@@Z) already defined in msvcprtd.lib(locale0_implib.obj)

libcpmtd.lib(locale0.obj) : error LNK2005: "private: static class std::locale::_Locimp * __cdecl std::locale::_Getgloballocale(void)" (?_Getgloballocale@locale@std@@CAPEAV_Locimp@12@XZ) already defined in msvcprtd.lib(MSVCP90D.dll)

libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_ctor(class std::_Locinfo *,class std::basic_string,class std::allocator > const &)" (?_Locinfo_ctor@_Locinfo@std@@SAXPEAV12@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) already defined in msvcprtd.lib(MSVCP90D.dll)

libcpmtd.lib(locale0.obj) : error LNK2005: "public: static void __cdecl std::_Locinfo::_Locinfo_dtor(class std::_Locinfo *)" (?_Locinfo_dtor@_Locinfo@std@@SAXPEAV12@@Z) already defined in msvcprtd.lib(MSVCP90D.dll)

libcpmtd.lib(xlock.obj) : error LNK2005: "public: __cdecl std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QEAA@H@Z) already defined in msvcprtd.lib(MSVCP90D.dll)

libcpmtd.lib(xlock.obj) : error LNK2005: "public: __cdecl std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QEAA@XZ) already defined in msvcprtd.lib(MSVCP90D.dll)

libcpmtd.lib(xmutex.obj) : error LNK2005: "public: void __cdecl std::_Mutex::_Lock(void)" (?_Lock@_Mutex@std@@QEAAXXZ) already defined in msvcprtd.lib(MSVCP90D.dll)

libcpmtd.lib(xmutex.obj) : error LNK2005: "public: void __cdecl std::_Mutex::_Unlock(void)" (?_Unlock@_Mutex@std@@QEAAXXZ) already defined in msvcprtd.lib(MSVCP90D.dll)

LIBCMTD.lib(setlocal.obj) : error LNK2005: _configthreadlocale already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(dbgheap.obj) : error LNK2005: _CrtSetCheckCount already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(crt0dat.obj) : error LNK2005: exit already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(crt0dat.obj) : error LNK2005: _exit already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(crt0dat.obj) : error LNK2005: _cexit already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(crt0dat.obj) : error LNK2005: _amsg_exit already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(crt0dat.obj) : error LNK2005: _initterm_e already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(lconv.obj) : error LNK2005: localeconv already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(tidtable.obj) : error LNK2005: _encode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(tidtable.obj) : error LNK2005: _decode_pointer already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(invarg.obj) : error LNK2005: _invalid_parameter already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(dbghook.obj) : error LNK2005: __crt_debugger_hook already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(crt0init.obj) : error LNK2005: __xi_a already defined in MSVCRTD.lib(cinitexe.obj)

LIBCMTD.lib(crt0init.obj) : error LNK2005: __xi_z already defined in MSVCRTD.lib(cinitexe.obj)

LIBCMTD.lib(crt0init.obj) : error LNK2005: __xc_a already defined in MSVCRTD.lib(cinitexe.obj)

LIBCMTD.lib(crt0init.obj) : error LNK2005: __xc_z already defined in MSVCRTD.lib(cinitexe.obj)

LIBCMTD.lib(hooks.obj) : error LNK2005: "void __cdecl terminate(void)" (?terminate@@YAXXZ) already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(winxfltr.obj) : error LNK2005: _XcptFilter already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(mlock.obj) : error LNK2005: _lock already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(mlock.obj) : error LNK2005: _unlock already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(sprintf.obj) : error LNK2005: sprintf_s already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(crt0.obj) : error LNK2005: mainCRTStartup already defined in MSVCRTD.lib(crtexe.obj)

LIBCMTD.lib(errmode.obj) : error LNK2005: __set_app_type already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(dbgrptw.obj) : error LNK2005: _CrtDbgReportW already defined in MSVCRTD.lib(MSVCR90D.dll)

LIBCMTD.lib(printf.obj) : error LNK2005: printf already defined in MSVCRTD.lib(MSVCR90D.dll)

LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library

LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library

D:\CudaApp\Dump1\libuse\x64\Debug\libuse.exe : fatal error LNK1169: one or more multiply defined symbols found







Thanks in advance…

You have a runtime library mismatch, some files are being compiled with /MT and some with /MD (or the debug variants). Then the linker tries to link to both libraries and you get conflicts.

Make sure all files are compiled with /MT (/MTd for debug builds)

You have a runtime library mismatch, some files are being compiled with /MT and some with /MD (or the debug variants). Then the linker tries to link to both libraries and you get conflicts.

Make sure all files are compiled with /MT (/MTd for debug builds)

well i am getting follwoing errors with /MTd built.

1>------ Build started: Project: callDLL, Configuration: Debug x64 ------

1>Linking…

1>dllTest1.lib(goCU.obj) : error LNK2019: unresolved external symbol cudaFree referenced in function “void __cdecl goCuda(void)” (?goCuda@@YAXXZ)

1>dllTest1.lib(goCU.obj) : error LNK2019: unresolved external symbol cudaMemcpy referenced in function “void __cdecl goCuda(void)” (?goCuda@@YAXXZ)

1>dllTest1.lib(goCU.obj) : error LNK2019: unresolved external symbol cudaGetLastError referenced in function “void __cdecl goCuda(void)” (?goCuda@@YAXXZ)

1>dllTest1.lib(goCU.obj) : error LNK2019: unresolved external symbol cudaConfigureCall referenced in function “void __cdecl goCuda(void)” (?goCuda@@YAXXZ)

1>dllTest1.lib(goCU.obj) : error LNK2019: unresolved external symbol cudaMemset referenced in function “void __cdecl goCuda(void)” (?goCuda@@YAXXZ)

1>dllTest1.lib(goCU.obj) : error LNK2019: unresolved external symbol cudaMalloc referenced in function “void __cdecl goCuda(void)” (?goCuda@@YAXXZ)

1>dllTest1.lib(goCU.obj) : error LNK2019: unresolved external symbol cudaSetupArgument referenced in function __device_stub__Z9acos_mainPi

1>dllTest1.lib(goCU.obj) : error LNK2019: unresolved external symbol __cudaRegisterFunction referenced in function _sti____cudaRegisterAll_39_tmpxft_00001810_00000000_6_goCU

cpp1_ii_5fe974cf

1>dllTest1.lib(goCU.obj) : error LNK2019: unresolved external symbol __cudaRegisterFatBinary referenced in function _sti____cudaRegisterAll_39_tmpxft_00001810_00000000_6_goCU

cpp1_ii_5fe974cf

1>dllTest1.lib(goCU.obj) : error LNK2019: unresolved external symbol __cudaUnregisterFatBinary referenced in function __cudaUnregisterBinaryUtil

1>dllTest1.lib(goCU.obj) : error LNK2019: unresolved external symbol cudaLaunch referenced in function “enum cudaError __cdecl cudaLaunch(char *)” (??$cudaLaunch@D@@YA?AW4cudaError@@PEAD@Z)

1>D:\CudaBuilts\callDLL\x64\Debug\callDLL.exe : fatal error LNK1120: 11 unresolved externals

1>callDLL - 12 error(s), 0 warning(s)

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The lib built was OK. But i am getting follwoing errors when i try to built the main exe.

Thanks Nabarun.

It looks like you’re not linking cudart.lib

Mac,

It is there in COnfigeration Properties->Linker->Input->Additional Dependencies->cudart.lib cutil64D.lib.

Anything else that i need to do.

Well i made some changes and it is working now but with dynamic linker.

Static linker is still a problem.

What do you mean by dynamic and static linker?

Also, make sure you’re linking to cudart.lib from CUDA/lib64, not CUDA/lib if you’re building a 64 bit app. Cutil libs are marked with 32 or 64, cudart libs are not. This might be an issue if, for example, you have CUDA/lib on the library search path (Tools->Options->Projects and solutions->VC++ Directories) or generally if the linker finds the 32 bit library before the 64.