Hi everone, I am new to CUDA…
I had the 2 errors even I am just doing simple program… like this:
error LNK2019: unresolved external symbol __Znaj referenced in function _main
fatal error LNK1120: 1 unresolved externals
can anyone help me?
Hi everone, I am new to CUDA…
I had the 2 errors even I am just doing simple program… like this:
error LNK2019: unresolved external symbol __Znaj referenced in function _main
fatal error LNK1120: 1 unresolved externals
can anyone help me?
i have written several programs
After clearing all syntax errors from compiling,
the same 2 errors appears.
Could you post a minimal source code that produces this problem along with the command line you are using to compile it?
just a simple vector sum program:
void vector_sum_gpu( float* a, float* b, float *c);
const int width = 200;
int main(int argc, char** argv)
{
float *arrayA = new float[width];
float *arrayB = new float[width];
float *arrayC = new float[width];
for(int i=0; i<width; i++ )
{
arrayA[i] = i;
arrayB[i] = i * 2;
}
vector_sum_gpu(arrayA, arrayB, arrayC);
for(int i=0; i<width; i++)
printf("%f \n", arrayC[i]);
CUT_EXIT(argc, argv);
}
void vector_sum_gpu( float* a, float* b, float *c)
{
CUT_DEVICE_INIT();
int size;
float *ptrA, *ptrB, *ptrC;
size = width * sizeof(float);
CUDA_SAFE_CALL(cudaMalloc((void**)&ptrA, size));
CUDA_SAFE_CALL(cudaMalloc((void**)&ptrB, size));
CUDA_SAFE_CALL(cudaMalloc((void**)&ptrC, size));
CUDA_SAFE_CALL(cudaMemcpy(ptrA, a, size, cudaMemcpyHostToDevice));
CUDA_SAFE_CALL(cudaMemcpy(ptrB, b, size, cudaMemcpyHostToDevice));
VectorSum<<< 1, width >>>( ptrA, ptrB, ptrC );
CUDA_SAFE_CALL(cudaMemcpy(c, ptrC, size, cudaMemcpyDeviceToHost));
CUDA_SAFE_CALL(cudaFree(ptrA));
CUDA_SAFE_CALL(cudaFree(ptrB));
CUDA_SAFE_CALL(cudaFree(ptrC));
}
kernel:
#ifndef _TEMPLATE_KERNEL_H_
#define _TEMPLATE_KERNEL_H_
#include <stdio.h>
__global__ void VectorSum( float* A, float* B, float* out )
{
int idx = threadIdx.x;
out[idx] = A[idx] + B[idx];
}
#endif
If you are compiling two separate files, add extern “C” to the VectorSum declaration
O…
I have added, but the errors still occur
Try to replace all “new” operators with malloc
At one point, I got similar errors (LNK2019) when my development environment
was skipping a .cu file, instead of running nvcc on it.
Check to make sure you’re running nvcc on all of your .cu files.
–redpill