I have a cuda file test.cu that include a file cuda.h.
the cuda.h contains the following function defintion used in test.cu.
extern void check_error(cudaError_t status);
this function is defined in cuda.c as follow:
void check_error(cudaError_t status)
{
cudaError_t status2 = cudaGetLastError();
if (status != cudaSuccess)
{
const char *s = cudaGetErrorString(status);
char buffer[256];
printf("CUDA Error: %s\n", s);
assert(0);
snprintf(buffer, 256, "CUDA Error: %s", s);
error(buffer);
}
if (status2 != cudaSuccess)
{
const char *s = cudaGetErrorString(status);
char buffer[256];
printf("CUDA Error Prev: %s\n", s);
assert(0);
snprintf(buffer, 256, "CUDA Error Prev: %s", s);
error(buffer);
}
}
I use Visual studio 2015 for compiling. cuda.c is compiled as a C file.
There is no Compilation errors. But I get the following linkage error:
test.cu.obj : error LNK2001: unresolved external symbol "void __cdecl check_error(enum cudaError)" (?check_error@@YAXW4cudaError@@@Z)
How to solve this error?
this is not a duplicate of Name mangling in CUDA and C++ because it ask about the reverse order. Call a C function from a Cuda code. in the above question it is for calling a cuda fuction from a C file.