I have a DLL that contains my CUDA code and recent added a pair .cuh/.cu with cuRAND code to be part of the DLL. Because there are a lot of linking problems regarding cuRAND, first I wrote a minimalist piece of code just to see if the thing links.
For the sake of completion, the .cuh and .cu are, respectively:
extern "C"
{
void simple_curand_test(void);
}
And
#include "GPU_Rand.cuh"
#include <curand.h>
#include <curand_kernel.h>
void simple_curand_test(void)
{
curandGenerator_t gen;
curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT);
}
Then, my compiler command to generate the DLL is:
nvcc -o bin\GPU_Methods.dll --shared src\GPU_Utils.cu src\GPU_Rand.cu -L"c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64" -lcurand
It ends with this error:
Creating library bin/GPU_Methods.lib and object bin/GPU_Methods.exp
tmpxft_000015a0_00000000-44_GPU_Rand.obj : error LNK2019: unresolved external symbol curandCreateGenerator referenced in function simple_curand_test
bin/SCS_GPU.dll : fatal error LNK1120: 1 unresolved externals
If I change the command to make the linker use the variable LIBRARIES, it looks like:
set LIBRARIES="c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64"
nvcc -o bin\GPU_Methods.dll --shared src\GPU_Utils.cu src\GPU_Rand.cu -lcurand
Then the error turns to:
nvlink fatal : Could not open input file 'c:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\lib\x64'
After spending some days reading and trying multiple combinations of parameters and commands, it is time to ask if you guys can spot what I am missing.
UPDATE - 01/06/2018
These are the environment variables in a command prompt that runs nvcc (some of them were omitted because they are not relevant to the issue and to avoid bloating your screen even more):
ALLUSERSPROFILE=C:\ProgramData
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1
CUDA_PATH_V9_1=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
NVCUDASAMPLES9_1_ROOT=C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1
NVCUDASAMPLES_ROOT=C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.1
NVTOOLSEXT_PATH=C:\Program Files\NVIDIA Corporation\NvToolsExt\
OS=Windows_NT
Path=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\libnvvp;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Windows Live\Shared;C:\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Programming\MSYS2\mingw64\bin;C:\Programming\Java\jdk1.8.0_162\bin;C:\Programming\Python365;C:\Programming\Python365\Lib;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\Hostx64\x64
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=5e03
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
PYTHONPATH=C:\Programming\Python365;C:\Programming\Python365\Lib
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\Windows
VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
windir=C:\Windows