CURAND linking error LNK2019: unresolved external symbol

I am trying to generate random numbers using the Host API Example in the CUDA Toolkit 4.0 CURAND Guide and I am encountering errors when I try to compile the .cu file with nvcc. The platform I am working on is Windows 7 and compiling through the Visual Studio 2008 x64 Win64 Command Prompt and CUDA is v3.2. The error I am getting is LNK2019: unresolved external symbol. From what I can tell, nvcc can’t find the functions built into CURAND. I assume it can find the curand.h file, since it doesn’t give me an error for that. I’ve added the proper paths to all the files in the cuda toolkit to the PATH environment variable in the system preferences (specifically: %CUDA_PATH%\bin, %CUDA_PATH%\lib\x64, %CUDA_PATH%\include). I can compile other .cu files which have CUDA functions such as dim3, cudaMalloc, cudaMemcpy, etc. I’ve tried compiling the .cu files which came in the CUDA SDK examples e.g. the Monte Carlo calculations of pi, and I get the same LNK2019 error. What is going wrong?

Below is the out put on the command prompt. The random.cu file is exactly the same as the Host API Example shown in the CUDA Toolkit 4.0 CURAND Guide (January 2011).

C:\Users\____\Documents\CUDA>nvcc random.cu

random.cu

tmpxft_00001158_00000000-3_random.cudafe1.gpu

tmpxft_00001158_00000000-8_random.cudafe2.gpu

random.cu

tmpxft_00001158_00000000-3_random.cudafe1.cpp

tmpxft_00001158_00000000-14_random.ii

tmpxft_00001158_00000000-15_random.obj : error LNK2019: unresolved external symbol curandDestroyGenerator referenced in function main

tmpxft_00001158_00000000-15_random.obj : error LNK2019: unresolved external symbol curandGenerateUniform referenced in function main

tmpxft_00001158_00000000-15_random.obj : error LNK2019: unresolved external symbol curandSetPseudoRandomGeneratorSeed referenced in function main

tmpxft_00001158_00000000-15_random.obj : error LNK2019: unresolved external symbol curandCreateGenerator referenced in function main

a.exe : fatal error LNK1120: 4 unresolved externals

I think you need to tell Visual Studio to link against the CURAND .lib / .dll.
I’m not sure about the exact setting for it–I think it is under Linker–>Input.

I’m using the command prompt, not the actual VS application. Is there any way to do it through the command prompt?

Edit: Managed to get it working in the VS application, but I’m still wondering if it can be done through the command prompt.

You can use the nvcc option -l to specify libraries to be linked against, and nvcc option -L to specify library paths.

Unresolved symbol error during the builiding, it is due to linking time and visual studio cannot locate the library file, for example curand.lib. Just go to linker to add on “curand.lib” as shown below:

  1. Goto to this place
    Project Properties → Linker → Input → Additional Dependencies

  2. Add on “curand.lib;”

It works.