Cuda: error C2065:"threadIdx':undeclared identifier

Hi all,

I am trying to create a Cuda project in VisualStudio 2010.I have created one simple test .cu file which take an array and add 1 to all its element and send back to the host.

I have added cudart.lib file to the Linker.

In the .cu code I have included “#include cuda_runtime.h” header.
Also I am using CUDA 4.2.I have selected the Cuda 4.2 in the Build Customization option by right clicking on the project.

But when I tried to compile it,firstly it gave two errors .

1)error C2065 :‘threadIdx’: undeclared identifier 2)error C2059: syntax error:’<’

Then in some Nvidia post ,somebody mentioned to change the Item Type file to CUDA C/C++.But after doing this it give two more errors:

3)error D8003: missing source filename …\Visual Studio 2010\Projects\MyFirstKernel\MyFirstKernel\cl

4)error MSB3721: The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\bin\nvcc.exe” -gencode=arch=compute_10,code=“sm_10,compute_10” --use-local-env --cl-version 2010 -ccbin “C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin” -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\include” -G --keep-dir “Debug” -maxrregcount=0 --machine 32 --compile -g -Xcompiler “/EHsc /nologo /Od /Zi /MDd " -o “Debug\” “…\Visual Studio 2010\Projects\MyFirstKernel\MyFirstKernel\”” exited with code 2. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 4.2.targets

Please help me to figure out the issue…

Thanks in advance.


Can you post the source code? or at least the kernel code. I’m not sure but i would also like to see the linker options and include directories of the visual studio… Maybe you’re forgetting something!

Bruno Faria

Here is the code .It is stired in *.cu file.

#include <cuda.h>
#include <cuda_runtime.h>

#include <stdio.h>
#include <stdlib.h>

global void myFirstKernel( int *a ,int *b,int N)
int i = threadIdx.x;
b[i] = a[i] +1;


int main(int argc, char * argv)
int *h_a;
int *h_b;
int N = 8;

for(int h=0;h<8;h++)

// pointer for device memory
    int *d_a;
int *d_b;

size_t memSize = 1 * N * sizeof(int);
    h_a = (int *) malloc(memSize);
h_b = (int *) malloc(memSize);

for(int h=0;h<8;h++)

    cudaMalloc(&d_a,memSize  );
cudaMalloc(&d_b,memSize  );


myFirstKernel<<<1, 8>>>(d_a,d_b,N);

    cudaMemcpy(h_b,d_b,memSize,cudaMemcpyDeviceToHost  );

    for (int j = 0; j < N; j++)

// free device memory

// free host memory

    return 0;


Also I have include 3 directories to the Linker.
1)C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\common\lib
2)C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\shared\lib
3)C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\lib

Also I have installed Nvidia Nsight Visual Edition and set the Item Type of .cu file as CUDA C/C++.