CURAND library - Compilation error - Undefined function reference

I have the following code that I am trying to compile using nvcc.

code:

#include <stdio.h> #include <stdlib.h> #include <cuda.h> #include <curand.h> int main(void) { size_t n = 100; size_t i; int *hostData; unsigned int *devData; hostData = (int *)calloc(n, sizeof(int)); curandGenerator_t gen; curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_MRG32K3A); curandSetPseudoRandomGeneratorSeed(gen, 12345); cudaMalloc((void **)&devData, n * sizeof(int)); curandGenerate(gen, devData, n); cudaMemcpy(hostData, devData, n * sizeof(int), cudaMemcpyDeviceToHost); for(i = 0; i < n; i++) { printf("%d ", hostData[i]); } printf("\n"); curandDestroyGenerator (gen); cudaFree ( devData ); free ( hostData ); return 0; } 

This is the result I get:

 $ nvcc -o RNG7 RNG7.cu /tmp/tmpxft_00005da4_00000000-13_RNG7.o: In function `main': tmpxft_00005da4_00000000-1_RNG7.cudafe1.cpp:(.text+0x6c): undefined reference to `curandCreateGenerator' tmpxft_00005da4_00000000-1_RNG7.cudafe1.cpp:(.text+0x7a): undefined reference to `curandSetPseudoRandomGeneratorSeed' tmpxft_00005da4_00000000-1_RNG7.cudafe1.cpp:(.text+0xa0): undefined reference to `curandGenerate' tmpxft_00005da4_00000000-1_RNG7.cudafe1.cpp:(.text+0x107): undefined reference to `curandDestroyGenerator' collect2: ld returned 1 exit status 

My initial guess is that, for some reason, the CURAND library is not installed properly or that it cannot find the curand.h header file.

Please let me know what I should look for or how to solve my problem.

Thanks!

+4
source share
2 answers

@Wilo Maldonado: just use the linker flag -lcurand and optionally -L / path / to / cuda / libs if you don't already have one

+9
source

The problem is not in the header file, otherwise you would have a compilation error. You have a linker error. You will need to tell your linker where to find the object or library file containing these functions.

0
source

All Articles