title: nvcc: error: identifier undefined, but it's defined
body: <p>I have a CUDA C code that when I try to compile it, nvcc complains with an undefined identifier error, but the variable it really exits!</p>
  
  <pre><code>extern "C"
  void vRand3f_cuda (vec3f *d_v, int n)
  {
  
      curandState *d_states;
      CUDA_CALL (cudaMalloc ((void **)&amp;d_states, n * sizeof (curandState)));
  
      dim3 gDim (1);
      dim3 bDim (n);
  
      set_seed&lt;&lt;&lt;gDim, bDim&gt;&gt;&gt; (d_states, time (NULL), n);
      vRand3f_cuda_generate&lt;&lt;&lt;gDim, bDim&gt;&gt;&gt; (d_v, d_states, n);
  
      CUDA_CALL (cudaFree (d_states));
  
  }
  
  __global__ void set_seed (curandState *states, unsigned long seed, int n)
  {
      int idx = threadIdx.x + blockIdx.x * gridDim.x;
      if (idx &gt;= n)
          return ;
  
      curand_init (seed, idx, 0, &amp;states[idx]);
  
  }
  
  __global__ void vRand3f_cuda_generate (vec3f *v, curandState *states, int n)
  {
      int idx = threadIdx.x + blockIdx.x * gridDim.x;
      if (idx &gt;= n)
  
      curandState localS = states[idx];
      double s, x, y;
      s = 2.;
  
      while (s &gt; 1.)
      {
          x = 2. - curand_uniform_double (&amp;localS) - 1.;
          y = 2. - curand_uniform_double (&amp;localS) - 1.;
          s = x * x   +   y * y;
      }
  
      v[idx].z = 1. - 2. * s;
      s = 2. * sqrt (1. - s);
      v[idx].x = s * x;
      v[idx].y = s * y;
  
      states[idx] = localS;
  }
  </code></pre>
  
  <p>I use the following line to compile:</p>
  
  <pre><code>nvcc -m64 -g -G `pkg-config --cflags glib-2.0`  -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -I/Developer/NVIDIA/CUDA-5.0/include -I. -o vec3-cuda.o -c vec3-cuda.cu
  </code></pre>
  
  <p>and I get the following:</p>
  
  <blockquote>
    <p>vec3-cuda.cu(58): warning: variable "localS" was declared but never
    referenced</p>
    
    <p>vec3-cuda.cu(64): error: identifier "localS" is undefined</p>
    
    <p>vec3-cuda.cu(74): error: identifier "localS" is undefined</p>
  </blockquote>
  
  <p>Any idea what happens here? I'm using CUDA 5 on OSX.</p>
  
  <p>Thank you.</p>