Unresolved Externals, Visual Studio Environment Setup

Hey all!

I’ve been trying to set up my visual studio to be compatible with CUDA for a while now–it’s been frustrating to say the least. I’ve been going through tons of environment setup walkthroughs and documentation, but seem to keep running into errors. Where I’m at now, is a bunch of unresolved external symbol errors over CUDA function calls.

Severity	Code	Description	Project	File	Line	Suppression State
Error (active)	E0029	expected an expression	simpletests	C:\Users\Tiger\code\simpletests\test1.cu	23	
Error	LNK2019	unresolved external symbol cudaFree referenced in function main	simpletests	C:\Users\Tiger\code\simpletests\test1.cu.obj	1	
Error	LNK2019	unresolved external symbol cudaMalloc referenced in function "enum cudaError __cdecl cudaMalloc<int>(int * *,unsigned __int64)" (??$cudaMalloc@H@@YA?AW4cudaError@@PEAPEAH_K@Z)	simpletests	C:\Users\Tiger\code\simpletests\test1.cu.obj	1	
Error	LNK2019	unresolved external symbol cudaLaunchKernel referenced in function "enum cudaError __cdecl cudaLaunchKernel<char>(char const *,struct dim3,struct dim3,void * *,unsigned __int64,struct CUstream_st *)" (??$cudaLaunchKernel@D@@YA?AW4cudaError@@PEBDUdim3@@1PEAPEAX_KPEAUCUstream_st@@@Z)	simpletests	C:\Users\Tiger\code\simpletests\test1.cu.obj	1	
Error	LNK2019	unresolved external symbol cudaMemcpy referenced in function main	simpletests	C:\Users\Tiger\code\simpletests\test1.cu.obj	1	
Error	LNK2019	unresolved external symbol __cudaPushCallConfiguration referenced in function main	simpletests	C:\Users\Tiger\code\simpletests\test1.cu.obj	1	
Error	LNK2019	unresolved external symbol __cudaPopCallConfiguration referenced in function "void __cdecl __device_stub__Z11AddIntsCUDAPiS_S_(int *,int *,int *)" (?__device_stub__Z11AddIntsCUDAPiS_S_@@YAXPEAH00@Z)	simpletests	C:\Users\Tiger\code\simpletests\test1.cu.obj	1	
Error	LNK2019	unresolved external symbol __cudaRegisterFatBinary referenced in function "void __cdecl __nv_cudaEntityRegisterCallback(void * *)" (?__nv_cudaEntityRegisterCallback@@YAXPEAPEAX@Z)	simpletests	C:\Users\Tiger\code\simpletests\test1.cu.obj	1	
Error	LNK2019	unresolved external symbol __cudaRegisterFatBinaryEnd referenced in function "void __cdecl __nv_cudaEntityRegisterCallback(void * *)" (?__nv_cudaEntityRegisterCallback@@YAXPEAPEAX@Z)	simpletests	C:\Users\Tiger\code\simpletests\test1.cu.obj	1	
Error	LNK2019	unresolved external symbol __cudaUnregisterFatBinary referenced in function "void __cdecl __cudaUnregisterBinaryUtil(void)" (?__cudaUnregisterBinaryUtil@@YAXXZ)	simpletests	C:\Users\Tiger\code\simpletests\test1.cu.obj	1	
Error	LNK2019	unresolved external symbol __cudaRegisterFunction referenced in function "void __cdecl __nv_cudaEntityRegisterCallback(void * *)" (?__nv_cudaEntityRegisterCallback@@YAXPEAPEAX@Z)	simpletests	C:\Users\Tiger\code\simpletests\test1.cu.obj	1	
Error	LNK1120	10 unresolved externals	simpletests	C:\Users\Tiger\code\simpletests\x64\Debug\simpletests.exe	1

I’ve already messed around with the project properties alot.
–Have tried both 2019 and 2017 platform toolsets
–cudart.lib and cuda.lib are included in Linker additional dependencies
–CudaToolkitLibDir is in Linker general additional library dependencies
→ Also tried putting these in the CUDA Linkers, no avail.
–Compute capabilities changed to the proper compute_61, sm_61 for my GPU (For some reason was initially set to 35, don’t know if this was intended or not…)
–Currently on my test code the includes are stdio.h, iostream, cuda_runtime.h, and device_launch_parameters.h
–Build parameters are all on x64

I’ve set up a fresh install of Windows 10, installed VS 2019 and CUDA Toolkit 10.1–all running on a system with a GTX1060. Not quite sure where to go from here, it’s definitely been frustrating. Hope someone can help out, would be much appreciated.

Chris

EDIT 1: I also tried to compile thru nvcc using the developer cmd for VS2019–I got a huge block of errors, that could be very useful in diagnosis, here are a few of the errors:

C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\vcruntime.h(184): error: invalid redeclaration of type name "size_t"

C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\vcruntime_new.h(49): error: first parameter of allocation function must be of type "size_t"

C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\vcruntime_new.h(54): error: first parameter of allocation function must be of type "size_t"

C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\type_traits(135): error: class template "std::_Is_function" has already been defined

C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\type_traits(135): error: class template "std::_Is_function" has already been defined

C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\type_traits(135): error: class template "std::_Is_function" has already been defined

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include\crt/common_functions.h(241): error: first parameter of allocation function must be of type "size_t"

C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xstring(4423): error: invalid second parameter type ("unsigned int") for literal operator; must be size_t

C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xstring(4428): error: invalid second parameter type ("unsigned int") for literal operator; must be size_t

C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xstring(4440): error: invalid second parameter type ("unsigned int") for literal operator; must be size_t

C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xstring(3988): here
            instantiation of "std::basic_string<_Elem, _Traits, _Alloc> &std::basic_string<_Elem, _Traits, _Alloc>::_Reallocate_for(std::basic_string<_Elem, _Traits, _Alloc>::size_type, _Fty, _ArgTys...) [with _Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>, _Fty=lambda [](char *, size_t, const char *)->void, _ArgTys=<const char *>]"
C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xstring(2823): here
            instantiation of "std::basic_string<_Elem, _Traits, _Alloc> &std::basic_string<_Elem, _Traits, _Alloc>::assign(const _Elem *, std::basic_string<_Elem, _Traits, _Alloc>::size_type) [with _Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]"
C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xstring(2276): here
            instantiation of "std::basic_string<_Elem, _Traits, _Alloc>::basic_string(const _Elem *, std::basic_string<_Elem, _Traits, _Alloc>::size_type) [with _Elem=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]"
C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xstring(4425): here

C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xmemory(862): error: no instance of function template "std::_Deallocate" matches the argument list
            argument types are: (char16_t *const, unsigned long long)
          detected during:
            instantiation of "void std::allocator<_Ty>::deallocate(_Ty *, size_t) [with _Ty=char16_t]"
C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xstring(3988): here
            instantiation of "std::basic_string<_Elem, _Traits, _Alloc> &std::basic_string<_Elem, _Traits, _Alloc>::_Reallocate_for(std::basic_string<_Elem, _Traits, _Alloc>::size_type, _Fty, _ArgTys...) [with _Elem=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>, _Fty=lambda [](char16_t *, size_t, const char16_t *)->void, _ArgTys=<const char16_t *>]"
C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xstring(2823): here
            instantiation of "std::basic_string<_Elem, _Traits, _Alloc> &std::basic_string<_Elem, _Traits, _Alloc>::assign(const _Elem *, std::basic_string<_Elem, _Traits, _Alloc>::size_type) [with _Elem=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>]"
C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xstring(2276): here
            instantiation of "std::basic_string<_Elem, _Traits, _Alloc>::basic_string(const _Elem *, std::basic_string<_Elem, _Traits, _Alloc>::size_type) [with _Elem=char16_t, _Traits=std::char_traits<char16_t>, _Alloc=std::allocator<char16_t>]"
C:\Program Files (x86)\Microsoft Visual Studio019\Community\VC\Tools\MSVC4.22.27905\include\xstring(4442): here

Etc.

Edit 2: Code generation tag (compute_61, sm_61) doesn’t seem to be having an effect on the Visual Studio building process, it executes with compute_35 and sm_35 regardless of my properties)

Partially resolved–I tried running with the built-in CUDA Runtime Project template, and my code worked. Trying to figure out why an empty file runs into issues.

cross posting:

[url]https://stackoverflow.com/questions/57540475/unresolved-externals-for-cuda-environment-setup[/url]